bslib icon indicating copy to clipboard operation
bslib copied to clipboard

Utility function for watching scss files and pushing updates

Open wch opened this issue 3 years ago • 1 comments

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.

wch avatar Oct 28 '20 19:10 wch

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.

cpsievert avatar Oct 28 '20 20:10 cpsievert