Flexdashboard= color of valuebox not changing

Dear Community,

I would like to change the color of one valuebox according by comparing the mean of a variable (here OverallYield) to a specific threshold (here = 80)

### Average Value (for selected options)
```{r}
renderValueBox({
  valueBox(round(mean(selectedData()$OverallYield)),
      if(round(mean(selectedData()$OverallYield)) >80){
          color = "green"
      } else {
          color = "red"
      })
})

With the code above, the word "green" or "red" appears depending on the threshold (80).
Any idea how i can link this to the valuebox color instead of words "green / red" ?
Note that: selectedData() is reactive.

Thanks

I would do it like this.

library(shiny)
library(shinydashboard)
ui <- dashboardPage(title = "Dummy",
                    dashboardHeader(title= "Dummy"), 
                    dashboardSidebar(
                      numericInput(inputId = "Num", label = "Number", value = 0, min = 0, max = 10, step = 1) 
                    ),
                    dashboardBody(
                      uiOutput("ValBox")
                    )#Close Body
) #Close Page
#End of ui

server <- function(input, output) {
  SqInput <- reactive({input$Num^2})
  
  output$ValBox <-  renderValueBox({
    if(SqInput() > 80){
      Mycolor = "green"
    } else {
      Mycolor = "red"
    }
    valueBox(SqInput(), subtitle = "Hi", color = Mycolor)
  })
  
}
shinyApp(ui = ui, server = server)

@FJCC .. Thanks a lot for providing this example !

Based on it, I've re-written mycode and I managed to get it done right with my dataset.
However, I must admit I didn't fully understand how the renderValueBox works. I'll try to figure it out with the documentations.

Michael

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.