Change color in shinydashboard

前端 未结 1 629
闹比i
闹比i 2021-01-14 20:19

I have the following which changes the color of the primary status in shinydashboard to the custom blue I have stated.

tags$style(HTML(\".box.box-solid.box-p         


        
相关标签:
1条回答
  • 2021-01-14 20:55

    I used the following style() statement at the beginning of the dashboardBody() tag to override every instance where color = "aqua" with your custom blue:

    tags$style(
      type = 'text/css', 
      '.bg-aqua {background-color: #005CB9!important; }'
    ),
    

    The key is the "!important" after the color, which overrides the shinydashboard preset.

    In the future, an easy way to identify css classes is to select "run external" in Rstudio when running your shinyapp, then use your browser's developer tools or "inspect element" tools.

    Here's the full example for context:

    require(shiny)
    require(shinydashboard)
    
    ui <- shinyUI(dashboardPage(
      dashboardHeader(title = 'Change infoBox color'),
      dashboardSidebar(disable = TRUE),
    
      dashboardBody(
        tags$style(
          type = 'text/css', 
          '.bg-aqua {background-color: #005CB9!important; }'
        ),
    
        infoBox(
          title = 'Custom Color',
          value = 100,
          color = 'aqua'
        )
      )
    ))
    
    server <- shinyServer(function(input, output) {
    
    })
    
    shinyApp(ui, server)
    
    0 讨论(0)
提交回复
热议问题