'How are you handling theme updates across multiple Shiny apps?

I have a general shiny question, rather than a specific call to help with code.

I've just finished creating a branded shiny template using a mix of fresh and some custom CSS. It's branded and looks sharp for the dashboards I'm building for my organisation. However, I've got one eye on how to maintain the look and feel of our dashboards as our analytics team continues to grow and mature. When we have 50 apps deployed and we want to change the theme, we will have to go through and update the code in 50 different shinyapps if we continue with the current method of fresh and custom CSS in www/.

Does anyone have experience in centralising themes? Perhaps serving CSS from somewhere external to Shiny and calling that at the start of app.R? This would likely require me to unify fresh and my additional custom CSS into a single .css file, but that's something I'm willing to do.

Alternatively, perhaps someone clever has already developed a package to solve this problem?

Any general pointers warmly received.



Solution 1:[1]

For those who might be interested, I built the theme into a package I was developing. Within my package's root dir, I added an inst folder and, inside that, a www dir. I added the organisation logo and some extra CSS that couldn't be easily configured with {fresh}.

To set the theme, I created a function like this:

set_theme<-function(){

  theme<-fresh::create_theme(

    fresh::adminlte_color(
      light_blue = "#383F48",
      aqua = "#094357",
      green = "#094357",
      blue = "#383F48"
    ),

    fresh::adminlte_global(
      box_bg = "#FFFFFF",
      info_box_bg = "#D1E0E5"
    ),

    fresh::adminlte_vars(
      "sidebar-width" = "275px",
      "sidebar-dark-bg" = "#3A3F46",
      "sidebar-dark-hover-color" = "#FFB151",
      "btn-border-radius" = "1px"
    )
  )

  shiny::addResourcePath('www', system.file("www", package = "myPackage"))

  return(theme)

}

I used shiny::addResourcePath to create a resource path to link the package's inst/www folder to the project within which myPackage::set_theme() is called. Then, within my Shiny dashboards:

library(myPackage)

theme <- myPackage::set_theme()

ui<-(
    fresh::use_theme(theme)
    ...
    tags$head(tags$link(rel = "stylesheet", type = "text/css", href = 
    "www/style.css"))
    ...
)

Make note of the www/ in the href argument. If you were to keep these files 'locally' within your Shiny app, you'd create a www dir in root and forego the www/ prefix. When calling files from your package, simply include the www/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1