Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R shinydashboard custom CSS to valueBox

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!

like image 853
Stuey.I Avatar asked Nov 17 '16 06:11

Stuey.I


1 Answers

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)
like image 190
Victorp Avatar answered Sep 22 '22 00:09

Victorp