diff --git a/inst/examples-shiny/brand.yml/app.R b/inst/examples-shiny/brand.yml/app.R index 7273c2edb..585db9d30 100644 --- a/inst/examples-shiny/brand.yml/app.R +++ b/inst/examples-shiny/brand.yml/app.R @@ -54,10 +54,30 @@ ui <- page_navbar( position = "right", open = "closed", width = "40%", - bg = "#0D1117", + bg = "var(--bs-dark)", + fg = "var(--bs-light)", card( - card_header("Edit", code("brand.yml"), class = "text-bg-secondary"), + card_header( + class = "text-bg-secondary hstack", + div("Edit", code("brand.yml")), + div( + class = "ms-auto", + tooltip( + tags$a( + class = "btn btn-link p-0", + href = "https://posit-dev.github.io/brand-yml/brand/", + target = "_blank", + bsicons::bs_icon( + "question-square-fill", + title = "About brand.yml", + size = "1.25rem" + ) + ), + "About brand.yml" + ) + ) + ), htmltools::tagAppendAttributes( textAreaInput( "txt_brand_yml", @@ -119,13 +139,19 @@ initBrandEditor()' ) ), - # if (getwd() != system.file("examples-shiny/brand.yml", package = "bslib")) { - actionButton( - "save", - label = span("Save", code("_brand.yml"), "file"), - class = "btn-outline-light" - ) - # } + if (Sys.getenv("R_CONFIG_ACTIVE") %in% c("shinylive", "shinyapps", "rsconnect", "rstudio_cloud")) { + shiny::downloadButton( + "download", + label = span("Download", code("_brand.yml"), "file"), + class = "btn-outline-light" + ) + } else if (getwd() != system.file("examples-shiny/brand.yml", package = "bslib")) { + actionButton( + "save", + label = span("Save", code("_brand.yml"), "file"), + class = "btn-outline-light" + ) + } ), nav_panel( @@ -373,10 +399,10 @@ server <- function(input, output, session) { }) observeEvent(input$save, { - req(brand_yml()) + validate( + need(input$txt_brand_yml, "_brand.yml file contents cannot be empty.") + ) - b <- brand_yml() - b$path <- NULL tryCatch( { writeLines(input$txt_brand_yml, "_brand.yml") @@ -386,6 +412,16 @@ server <- function(input, output, session) { ) }) + output$download <- downloadHandler( + filename = "_brand.yml", + content = function(file) { + validate( + need(input$txt_brand_yml, "_brand.yml file contents cannot be empty.") + ) + writeLines(input$txt_brand_yml, file) + } + ) + PlotTask <- ExtendedTask$new(function(x_max, y_factor) { x <- seq(0, x_max, length.out = 100) y <- sin(x) * y_factor