0

When I run my Shiny App I receive the following "Error: missing value where TRUE/FALSE needed" where the ValueBox is not showing.

I reviewed the code and checked if others have the same issue, can you please advise what is wrong in the code below. I appreciate your help

output$lv.rsk <- renderValueBox({
    
    emp.pred_df = ml.out %>%
      dplyr::filter(Employee.ID == input$EmpInput)
    emp.risk = as.numeric(emp.pred_df$p1)*100
    
    if(emp.risk<10){
      
      valueBox( paste(emp.risk, "%")
                ,subtitle = tags$p("No Risk of Leaving", style = "font-weight: bold;font-size: 20px")
                ,icon = icon("street-view")
                ,color = "blue")
    } else if (emp.risk >=10 && emp.risk <= 50) {
      
      valueBox( paste(emp.risk, "%")
                ,subtitle = tags$p("Low Risk of Leaving", style = "font-weight: bold;font-size: 20px")
                ,icon = icon("street-view")
                ,color = "green")
      
    } else if (emp.risk >=50 && emp.risk <= 70) {
      
      valueBox( paste(emp.risk, "%")
                ,subtitle = tags$p("Medium Risk of Leaving", style = "font-weight: bold;font-size: 20px")
                ,icon = icon("street-view")
                ,color = "orange")
      
    } else if (emp.risk>70) {
      
      valueBox( paste(emp.risk, "%")
                ,subtitle = tags$p("High Risk of Leaving", style = "font-weight: bold;font-size: 20px")
                ,icon = icon("street-view")
                ,color = "red")
    }
       
  })

hsalkhatib
  • 15
  • 3
  • 1
    Where does the `valueBox()` function come from? It seems like the value of `emp.risk` is not being set. Are you sure `emp.pred_df$p1` exists? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Oct 19 '20 at 04:00
  • 1
    This error happens when an `NA` is used in an `if` condition : you could add `cat(emp.risk)` before `if` to debug content of `emp.risk` in console. – Waldi Oct 19 '20 at 05:07

0 Answers0