mardi 24 novembre 2020

How do I change the color of an infobox in shinydashboard based on a string, not a value?

I have been trying to change the color of the InfoBox if the entry is "x" or "y". I found this question here: How do I change the color of an infobox in shinydashboard based on the value displayed. The answer given works for numerical data, but I can't get to work with string. Here is a reproducible code that works with numerical values.

```{r library and source, eval= FALSE }

library(shiny)
library(shinydashboard)

```


```{r UI, eval = FALSE}
ui <- dashboardPage(
  #Header
  dashboardHeader(title = "dashboard"),
  
  #Sidebar with download button
  dashboardSidebar(width = 130),
  
  #Body
  dashboardBody ((box
                  (
                    width = 6,
                    textInput("wt1", " Choose wt:", "")
                  )),
                 
                 infoBoxOutput("Output"))
)

```

```{r Server, eval = FALSE}

server <- function(input, output, session) {
  output$Output <- renderInfoBox({
    InfoTotal <- paste(input$wt1, "")
    
    if (input$wt1 > 2)
    {
      infoBox(
        "Change colors, please",
        InfoTotal,
        icon = icon("tint", lib = "glyphicon"),
        color = "red"
      )
    }
    else
      
    {
      infoBox(
        "Change colors, please",
        InfoTotal,
        icon = icon("tint", lib = "glyphicon"),
        color = "blue"
      )
    }
    
    
  })
  
  
}

shinyApp(ui, server)

```

Also, it doesn't work for me is I try if (input$wt1 = 2) instead of > 2. Any ideas?

Aucun commentaire:

Enregistrer un commentaire