Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session$setCurrentTheme should throw an error when trying to dynamically update to a different bootstrap version. #3202

Closed
nstrayer opened this issue Dec 11, 2020 · 1 comment
Milestone

Comments

@nstrayer
Copy link
Contributor

nstrayer commented Dec 11, 2020

Issue

If you're using session$setCurrentTheme() and bslib::bs_theme() together to do dynamic theming, if there is a version mismatch between the original theme and the newly updated dynamic one (such as forgetting to set version in the update code) the theme change will silently change.

Proposed fix

Check to make sure that a dynamic update does not try and change the bootstrap version and throw an error if it does.

Demo app

The following demonstrates the problem. Switching the theme won't work when the version is set to 4 because the initial chosen version was 3. Once you switch the version to 3, then the bootswatch changing starts working.

Steps to reproduce:

  • Change theme radio button to "flatly"

    • Nothing will happen
      image
  • Change the version radio button to '3'

    • Theme changes now respected
      image

app.R

library(shiny)
library(bslib)

# Setting version to 3 here
my_theme <- bs_theme(bootswatch = "darkly", version = "3")
ui <- fluidPage(
  theme = my_theme,
  radioButtons("current_theme", "Choose a theme for bslib",
               choices = c("darkly", "flatly")),
  radioButtons("bs_version", "Bootstrap version", choices = c("4", "3")),
)

server <- function(input, output, session) {
  observe({
    session$setCurrentTheme(
      bs_theme(bootswatch = input$current_theme, version = input$bs_version)
    )
  })
}

shinyApp(ui, server)
@cpsievert
Copy link
Collaborator

Closed via #3210

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

No branches or pull requests

2 participants