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

ViviG

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?

Ash

Use two equal signs, e.g. if (input$wt1 == 2) or if (input$wt1 == "red")

R treats = differently to ==. The first is for assigning things while the second is for testing whether two things are equal.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change barchart color based on frequency value

How do i do multiple checks on a props value in order to change the color of that value. Inside of style={ }?

Change color in shinydashboard

How do I change the value of an appended string?

How do I change value in a pandas series based on condition

How do change the color of subtext value in flutter

How do I change the color of a column based on the color of other column?

How do I change color's hue, saturation, or value in Flutter?

Angular: How do I change value based on key value

How can I change the color based on my grouping value instead of fill value in ggplot in R?

change color based on the string value

how do i implement google maps infobox

How do I get a table value based on the value of another string?

How do I change the value of a cell based on the position of a team in a table?

How do I change the color on my noUiSliders depending on the value it currently is at?

How to change color of text based on $value

How do I change element value based on the data attribute?

How do I change color of interactions based on interaction value using an ifelse() statement in an plotweb bipartite?

How do I get color value from a color wheel based on X & Y coordinates?

How do I change the color of a row based on specific dates?

How do i change input field background color based on onclick?

How can I change the background color of a row based on the value using HTML, CSS and JavaScript?

How do I center, change the color and font of this string?

How to create Infobox as actionbutton in Shinydashboard?

How do i change the color of an appended string?

How do I change the value of the string in C#?

How do I change the value of a variable inside a string?

How can I change ChartJS line color based on the value?

How do I split a string based on a numeric value follow by a dot '.'?