R shiny - background of sidebar panel

后端 未结 2 1395
感动是毒
感动是毒 2020-12-09 04:29

Let\'s say, I\'ve got a simple shiny application and I would like to change sidebar panel background. I\'ve tried with css, but I\'ve managed only to change the whole

2条回答
  •  一向
    一向 (楼主)
    2020-12-09 05:01

    Try this:

    library(shiny)
    
    ui <- shinyUI(fluidPage(
      tags$head(tags$style(
        HTML('
             #sidebar {
                background-color: #dec4de;
            }
    
            body, label, input, button, select { 
              font-family: "Arial";
            }')
      )),
      titlePanel("Hello Shiny!"),
    
      sidebarLayout(
        sidebarPanel(id="sidebar",
          sliderInput("bins",
                      "Number of bins:",
                      min = 1,
                      max = 50,
                      value = 30)
        ),
    
        mainPanel(
          plotOutput("distPlot")
        )
      )
    ))
    
    server <- shinyServer(function(input, output) {
    
      output$distPlot <- renderPlot({
        x    <- faithful[, 2]  # Old Faithful Geyser data
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })
    
    })
    
    shinyApp(ui=ui,server=server)
    

    The sidebar doesn't have any other attributs than 'col-sm-4' when initialized so you can either use jQuery and some logic to figure out which is the propper column to color (so that we only set the background of the sidebar), or you can give a id to the form nested in the column and color the background of this form.

提交回复
热议问题