Search code examples
rshinydashboardshinydashboard

Shiny: can't add color, icon or subtitle to my valuebox


I built my first dashboard using shiny and I wanted to add some valueboxs but when I did it the valuebox appeared without color or subtitle or icon. enter image description here

I can't figure out what is the error. Please help and thanks in advance.

Here's the code I wrote:

library(shiny)
library(shinydashboard)
library(flexdashboard)
library(readxl)
Base_Ferias <- read_excel("C:/Users/tomas/Desktop/R/Apps/Seguimiento_ferias/Base_Avance_Ferias.xlsx")
Base_Ferias$T_respuesta <- as.numeric(Base_Ferias$T_respuesta)



ui <-dashboardPage(skin = "red",
                   dashboardHeader(title = "My Dashboard", titleWidth = 450),
                   dashboardSidebar(selectInput("actividad", "Select", 
                                                choices = Base_Ferias$Actividad)),
                   dashboardBody(
                     box(flexdashboard::gaugeOutput("chart"),width=200,
                                  title="Percentage"),
                     box(valueBoxOutput("value1"), height = "100px", width = 3)

                     )
                   )



server <- shinyServer(function(input, output, session) {

  output$chart <- flexdashboard::renderGauge({
    x <- Base_Ferias[Base_Ferias$Actividad==input$actividad,]
    y <- x$T_respuesta
    gauge(y, min = 0, max = 100, symbol = '%')
    })

  output$value1 <- renderValueBox({
    valueBox(
      paste0(25,"%"), "subtitle",icon("stats",lib='glyphicon'),
             color = "purple")
  })
})

shinyApp(ui = ui, server = server)

Solution

  • Attaching flexdashboard last masks functions with the same name from shinydashboard. Use valueBox from shinydashboard instead:

    library(shiny)
    library(shinydashboard)
    #> 
    #> Attaching package: 'shinydashboard'
    #> The following object is masked from 'package:graphics':
    #> 
    #>     box
    
    ui <-dashboardPage(skin = "red",
                       dashboardHeader(title = "My Dashboard", titleWidth = 450),
                       dashboardSidebar(selectInput("actividad", "Select", 
                                                    choices = c("one", "two"))),
                       dashboardBody(
                         box(flexdashboard::gaugeOutput("chart"),width=200,
                             title="Percentage"),
                         box(valueBoxOutput(outputId = "value1"))
    
                       )
    )
    
    
    
    server <- shinyServer(function(input, output, session) {
    
      output$chart <- flexdashboard::renderGauge({
        x <- 1
        y <- 10
        flexdashboard::gauge(y, min = 0, max = 100, symbol = '%')
      })
    
      output$value1 <- renderValueBox({
        valueBox(
          paste0(25,"%"), "subtitle",icon("stats",lib='glyphicon'),
          color = "purple")
        })
    })
    
    shinyApp(ui = ui, server = server)
    #> 
    #> Listening on http://127.0.0.1:5809
    

    Created on 2020-03-04 by the reprex package (v0.3.0)