Skip to content

Commit 9790265

Browse files
committed
feat(example-brand): Improve path handling, styles, more
1 parent f2fc475 commit 9790265

File tree

1 file changed

+21
-10
lines changed
  • inst/examples-shiny/brand.yml

1 file changed

+21
-10
lines changed

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

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

19-
theme_brand <- bs_theme(brand = TRUE)
19+
theme_brand <- bs_theme()
2020

2121
brand <- attr(theme_brand, "brand")
22+
BRAND_PATH <- brand$path %||% "_brand.yml"
2223

2324
theme_set(theme_minimal())
2425

2526
if (requireNamespace("thematic", quietly = TRUE)) {
26-
if (!is.null(brand)) {
27+
base_font <- bslib:::brand_pluck(brand, "typography", "base", "family")
28+
if (!is.null(base_font)) {
2729
# TODO: Update plot fonts dynamically
28-
thematic::thematic_shiny(
29-
font = bslib:::brand_pluck(brand, "typography", "base", "family")
30-
)
30+
thematic::thematic_shiny(font = base_font)
3131
} else {
3232
thematic::thematic_shiny()
3333
}
@@ -77,6 +77,7 @@ ui <- page_navbar(
7777
width = "40%",
7878
bg = "var(--bs-dark)",
7979
fg = "var(--bs-light)",
80+
`data-bs-theme` = "dark",
8081

8182
card(
8283
card_header(
@@ -103,7 +104,9 @@ ui <- page_navbar(
103104
textAreaInput(
104105
"txt_brand_yml",
105106
label = NULL,
106-
value = paste(readLines("_brand.yml", warn = FALSE), collapse = "\n"),
107+
value = if (!is.null(brand)) {
108+
paste(readLines(brand$path, warn = FALSE), collapse = "\n")
109+
},
107110
width = "100%",
108111
height = "80%",
109112
rows = 20
@@ -165,13 +168,21 @@ initBrandEditor();
165168
if (use_download_button) {
166169
shiny::downloadButton(
167170
"download",
168-
label = span("Download", code("_brand.yml"), "file"),
171+
label = span(
172+
"Download",
173+
code("_brand.yml", style = "color: currentColor"),
174+
"file"
175+
),
169176
class = "btn-outline-light"
170177
)
171178
} else {
172179
actionButton(
173180
"save",
174-
label = span("Save", code("_brand.yml"), "file"),
181+
label = span(
182+
"Save",
183+
code("_brand.yml", style = "color: currentColor"),
184+
"file"
185+
),
175186
class = "btn-outline-light"
176187
)
177188
}
@@ -397,7 +408,7 @@ server <- function(input, output, session) {
397408
tryCatch(
398409
{
399410
b <- yaml::yaml.load(brand_yml_text())
400-
b$path <- normalizePath("_brand.yml")
411+
b$path <- normalizePath(BRAND_PATH, mustWork = FALSE)
401412
brand_yml(b)
402413
},
403414
error = error_notification(
@@ -428,7 +439,7 @@ server <- function(input, output, session) {
428439

429440
tryCatch(
430441
{
431-
writeLines(input$txt_brand_yml, "_brand.yml")
442+
writeLines(input$txt_brand_yml, BRAND_PATH)
432443
showNotification(markdown("Saved `_brand.yml`!"))
433444
},
434445
error = error_notification("Could not save `_brand.yml`.")

0 commit comments

Comments
 (0)