else If statement not working on shinyapps.io

Greetings all,

I need help for an issue in shinyapps.io with else if statement.
This is my code :

req51<- data.frame(req5)
t<- nrow(req51)
x <- data.frame(classe=1:t, id=rep(1, t))

for (i in 1:t) {
if (req51[i,"Age"]<30) {x[i, "classe"] = "20-30"}
else if (req51[i,"Age"]<40) {x[i, "classe"] = "30-40"}
else if (req51[i,"Age"]<50) {x[i, "classe"] = "40-50"}
else {x[i, "classe"] = "50-60"}

When i run this locally it works well, but when i deploy the app on shinyapps.io i get the following error :

Warning: Error in if: missing value where TRUE/FALSE needed.

I dont really know what is going wrong.

Can somebody help please?



We don't really have enough info to help you out. Could you post the content of your logs and ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Please have a look at this guide, to see how to create one for a shiny app

Dear @andresrcs thank you for your reaction. I finally understood the issue. It comes from the use of IF statement inside the FOR loop. I was able to solve it by using the "IFELSE" statement instead. Thanks.

If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.