R Shiny: interactively change the theme of the application

I am trying to find a way to interactively change the theme of an application from text input.

Here is an example of my ui.R.

shinyUI(fluidPage(
  tabsetPanel(
    tabPanel("Main"),
    tabPanel("Settings",
      textInput("skin", "Select Skin", value = "bootstrap1.css")
    ), type = "pills", position = "above"
   ),theme = input$skin
  )
)

I get the following error: "ERROR: object" input "not found"

As a final note, I created the www folder in the application folder, which contains bootstrap1.css among other css files.

+4
source share
1 answer

The parameter themein fluidPageinserts a CSS script with the following call:

tags$head(tags$link(rel = "stylesheet", type = "text/css", 
                            href = input$Skin))

You can simply add this html as a reactive element to your ui:

library(shiny)
runApp(list(ui = fluidPage(
  tabsetPanel(
    tabPanel("Main"),
    tabPanel("Settings",
             textInput("Skin", "Select Skin", value = "bootstrap1.css")
    ), type = "pills", position = "above"
  ), 
  uiOutput("myUI")
)
, server = function(input, output, session){
  output$myUI <- renderUI({
    tags$head(tags$link(rel = "stylesheet", type = "text/css", 
                        href = input$Skin))
  })
}
))
+5
source

All Articles