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
Change the version radio button to '3'
Theme changes now respected
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)
Issue
If you're using
session$setCurrentTheme()
andbslib::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 setversion
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"
Change the version radio button to '3'
app.R