Skip to content

Commit

Permalink
brand: Use download button in example app when deployed (#1163)
Browse files Browse the repository at this point in the history
* feat: Add link to editor header to brand.yml structure

* chore: restore code to avoid saving if running in pkg dir

* feat: Use a download button if deployed on posit hosted products

* chore: Use dark bg color for sidebar
  • Loading branch information
gadenbuie authored Jan 9, 2025
1 parent 2e6c8d4 commit 7b1f15a
Showing 1 changed file with 48 additions and 12 deletions.
60 changes: 48 additions & 12 deletions inst/examples-shiny/brand.yml/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 7b1f15a

Please sign in to comment.