9

I have been trying to change the color of the valueBox to a custom color (beyond those available in validColors) but have been unable to do so. I understand there is a way of using tags to include custom CSS however I haven't been able to put them in the right place.

ui<- dashboardPage(   
                dashboardHeader(),  
                 dashboardSidebar(),  
                 dashboardBody(  
                           fluidRow(valueBoxOutput("name")  
                             )))

 server<- function(input, output){  
  output$name<- renderValueBox({ valueBox(  
    ("example"), subtitle = "Subtitle text",color="blue")}  
  )}

Any help much appreciated!

Bharat
  • 2,441
  • 3
  • 24
  • 36
Stuey.I
  • 133
  • 1
  • 1
  • 6

1 Answers1

20

Hi you can overwrite a CSS class to add a custom color with tags$style in the ui like below, modify background-color for the box color (here a flashy yellow) and color for the text color. Here only box with color = "yellow" will be modified since only the class .small-box.bg-yellow is updated.

library("shiny")
library("shinydashboard")

ui<- dashboardPage(
  dashboardHeader(),  
  dashboardSidebar(),  
  dashboardBody(
    tags$style(".small-box.bg-yellow { background-color: #FFFF00 !important; color: #000000 !important; }"),
    fluidRow(
      valueBoxOutput("name1"), 
      valueBoxOutput("name2")
    )
  )
)

server<- function(input, output){
  output$name1 <- renderValueBox({
    valueBox("example", subtitle = "Subtitle text", color = "yellow")
  })
  output$name2 <- renderValueBox({
    valueBox("example", subtitle = "Subtitle text", color = "blue")
  })
}
shinyApp(ui = ui, server = server)
Victorp
  • 13,636
  • 2
  • 51
  • 55
  • 1
    Thanks Victorp, just what I was after. Cheers. – Stuey.I Nov 18 '16 at 04:13
  • Hi! What happens if I want to make this change inside my script .css? I am trying with this `.small-box.bg-yellow { background-color: #FFFF00 !important; color: #000000 !important; }`but nothing is changing – coding Jul 16 '20 at 19:21
  • Do you have a `valueBox` with `color = "yellow"` ? The `bg-yellow` in the CSS comes from the color argument – Victorp Jul 17 '20 at 07:28
  • How do you intuitively know what the css tag is?! This is part is so confusing to me. – ethan tenison May 07 '21 at 19:15
  • 1
    @ethan tenison You can find a good tutorial here: https://unleash-shiny.rinterface.com/beautify-css.html – Victorp May 10 '21 at 07:45