Skip to contents

Read the theme currently applied in the browser – its preset and dark-mode flag – inside a reactive context. The asset layer reports this as a hidden input on load and whenever the theme changes, so a renderPlot() that calls shad_current_theme() re-executes on every dark toggle or preset switch.

Usage

shad_current_theme(session = shiny::getDefaultReactiveDomain())

Arguments

session

The Shiny session.

Value

A list with preset (character or NULL) and dark (logical).

Examples

if (interactive()) {
  ui <- page_shad(
    shad_select("preset", "Theme", selected = "slate",
                choices = c("slate", "blue", "rose")),
    shiny::plotOutput("plot")
  )
  server <- function(input, output, session) {
    shiny::observe(update_shad_theme(preset = input$preset))
    output$plot <- shiny::renderPlot({
      th <- shad_current_theme()
      plot(1:10, pch = 19, col = shad_chart_colors(1, th$preset, th$dark))
    }, bg = "transparent")
  }
  shiny::shinyApp(ui, server)
}