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())See also
Other shadshiny theming:
shad_chart_colors(),
shad_theme(),
shad_theme_echarts4r(),
shad_theme_from_registry(),
shad_theme_ggplot2(),
shad_theme_plotly(),
shad_theme_scope(),
shad_tokens()
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)
}