rstudio / bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
https://rstudio.github.io/bslib/
Other
491 stars 58 forks source link

Utility function for watching scss files and pushing updates #140

Open wch opened 4 years ago

wch commented 4 years ago

If someone has a Shiny application and wants to test out changes to a scss file with live changes, it would be useful to have a function that does something like this (I probably don't have all the details right, but this is the general idea):

r <- reactiveFileReader(500, session, "mytheme.scss", function(file) {
  file
})

observe({
  mytheme <- sass::sass_file(r())
  # If we had a reactive getCurrentTheme(), that would be good here
  theme <- bs_bundle(getCurrentTheme(), mytheme)
  session$setCurrentTheme(theme)
})

In the case where someone uses a Bootswatch theme, this would be really helpful, since the real-time themer in bootstraplib doesn't work well with the way variables are used in Bootswatch.

cpsievert commented 4 years ago

Maybe setCurrentTheme() could have watch arg which would crawl the theme searching for sass::sass_file()s replacing them with a reactiveFileReader() version

observe({
  session$setCurrentTheme(theme, watch = TRUE)
})

BTW, this idea seems generally useful for sass + shiny, not just for bootstraplib.