Getting an Error (Error in dist == "Humidity" : comparison (1) is possible only for atomic and list types) while creating a Shiny web app in R

shiny
r
web_application
rstudio
histogram

#1

Hello,

I am trying to create a simple web app using shiny in R and using the following code along with my dataset in train variable

library(shiny)
ui=fluidPage(plotOutput(outputId=“hist”),radioButtons(inputId=“dist”, “Distribution type:”,
c(“Humidity” = “train$humidity”,
“Temperature” = “train$temp”,
“Windspeed” = “train$windspeed”,
“Felt temperature” = “atemp”)))
server=function(input,output)
{
output$hist=renderPlot({
if(dist==“Humidity”)
hist(train$humidity)
else if(dist==“Temperature”)
hist(train$temp)
else if(dist==“Windspeed”)
hist(train$windspeed)
else if(dist==“Felt temperature”)
hist(train$atemp)
})
}
shinyApp(ui=ui,server=server)

But I get an error saying

Error in dist == “Humidity” :
comparison (1) is possible only for atomic and list types

I want the histogram to display the distribution of the desired variable which we select using the radio buttons. how to remove this error?

Thanks.


#2

@pravin, I just got the same error now in a dataset I’m working on, due to a different, simpler problem. (While comparing a variable to boolean values – turns out the variable wasn’t created in the first place because I forgot to import a library.) Make sure that dist is properly defined.