Skip to content

Commit f2fc475

Browse files
committed
fix(example): Correctly use download or save button
1 parent 4aefcf2 commit f2fc475

File tree

1 file changed

+28
-13
lines changed
  • inst/examples-shiny/brand.yml

1 file changed

+28
-13
lines changed

inst/examples-shiny/brand.yml/app.R

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ options(
1616
# shiny.autoreload.pattern = "_brand[.]yml|app[.]R|[.]s?css" ## TODO: Enable after fixing autoreload
1717
)
1818

19-
if (!file.exists("Monda.ttf")) {
20-
download.file(
21-
"https://github.com/google/fonts/raw/48db77e32954f6f5e65a7122ecbe8a2093c4f5d7/ofl/monda/Monda%5Bwght%5D.ttf",
22-
"Monda.ttf"
23-
)
24-
download.file(
25-
"https://github.com/google/fonts/raw/48db77e32954f6f5e65a7122ecbe8a2093c4f5d7/ofl/monda/OFL.txt",
26-
"Monda-OFL.txt"
27-
)
28-
}
29-
3019
theme_brand <- bs_theme(brand = TRUE)
3120

3221
brand <- attr(theme_brand, "brand")
@@ -44,11 +33,37 @@ if (requireNamespace("thematic", quietly = TRUE)) {
4433
}
4534
}
4635

36+
use_download_button <- FALSE
37+
38+
# ---- For hosted demo, delete if local ----
4739
is_app_hosted <-
4840
Sys.getenv("R_CONFIG_ACTIVE") %in%
4941
c("shinylive", "shinyapps", "rsconnect", "rstudio_cloud")
5042
is_app_packaged <-
51-
getwd() != system.file("examples-shiny/brand.yml", package = "bslib")
43+
getwd() == system.file("examples-shiny/brand.yml", package = "bslib")
44+
use_download_button <- is_app_hosted || is_app_packaged
45+
46+
if (bslib:::brand_has(brand, "typography", "fonts")) {
47+
tryCatch(
48+
{
49+
if (brand$typography$fonts[[2]]$files[[1]]$path == "Monda.ttf") {
50+
if (!file.exists("Monda.ttf")) {
51+
download.file(
52+
"https://github.com/google/fonts/raw/48db77e32954f6f5e65a7122ecbe8a2093c4f5d7/ofl/monda/Monda%5Bwght%5D.ttf",
53+
"Monda.ttf"
54+
)
55+
download.file(
56+
"https://github.com/google/fonts/raw/48db77e32954f6f5e65a7122ecbe8a2093c4f5d7/ofl/monda/OFL.txt",
57+
"Monda-OFL.txt"
58+
)
59+
}
60+
}
61+
},
62+
error = function(err) {
63+
}
64+
)
65+
}
66+
# ---- For hosted demo, delete if local ----
5267

5368
ui <- page_navbar(
5469
theme = bs_add_rules(theme_brand, sass::sass_file("_colors.scss")),
@@ -147,7 +162,7 @@ initBrandEditor();
147162
)
148163
),
149164

150-
if (is_app_hosted || is_app_packaged) {
165+
if (use_download_button) {
151166
shiny::downloadButton(
152167
"download",
153168
label = span("Download", code("_brand.yml"), "file"),

0 commit comments

Comments
 (0)