Skip to content

Conversation

@wch
Copy link
Collaborator

@wch wch commented Oct 28, 2020

This adds a method session$getCurrentTheme(), which is reactive and returns the current theme for the session.

We may want to tweak the interface, but this works.

remotes::install_github('rstudio/shiny@wch-reactive-theme')

Demo app:

library(shiny)
library(bootstraplib)

shinyApp(
  ui = fluidPage(
    theme = bs_theme(bootswatch = "darkly"),
    selectInput("theme", "Select theme", choices = c("darkly", "sketchy", "solar", "lux")),
    numericInput("n", "n", 1),
    sliderInput("slider", "Slider Input", 1, 10, 5),
    p("This is some text"),
    br(),
    verbatimTextOutput("theme_info")
  ),
  server = function(input, output, session) {
    observe({
      theme <- bs_theme(bootswatch = input$theme)
      session$setCurrentTheme(theme)
    })
    
    output$theme_info <- renderPrint({
      print(Sys.time())
      session$getCurrentTheme()
    })
  }
)

@cpsievert cpsievert modified the milestones: 1.5.1, 1.6 Oct 30, 2020
@cpsievert cpsievert self-requested a review November 11, 2020 01:03
Copy link
Collaborator

@cpsievert cpsievert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the mock session method is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants