Search code examples
shinyshinythemes

How to modify the themes of shinythemes?


How to modify the themes of shinythemes? For example, let us assume I want to change darkly's background black.

library(shiny)
library(shinythemes)

ui <- fluidPage(
  theme = shinytheme("darkly"),
  "How to change this black?")

server <- function(input, output) {}

shinyApp(ui, server)

I guess one solution would be to copy the CSS of darkly with the modified black to the www-folder of my app and then use theme = "darkly_modified_black.css". Is there a simpler solution I am missing?


Solution

  • You can include your own css-arguments, if you just want to change the background-color. But yes, you can also copy the css of darkly, modify it, include it in the www folder and load it from there.

    library(shiny)
    library(shinythemes)
    
    css <- HTML(" body {
        background-color: #000000;
    }")
    
    ui <- fluidPage(
      tags$head(tags$style(css)),
      theme = shinytheme("darkly"),
      "How to change this black?")
    
    server <- function(input, output) {}
    
    shinyApp(ui, server)
    

    If you want a separate .css-file you can use includeCSS with the path to the file.