Shiny Dashboard, Interactive plots,

Hi all,

I'm trying to create an interactive dashboard. However, I have encountered some problems. What I aim to achieve is that the user can have two inputs, which will then be converted in to a scatterplot with only the data of these two inputs.

However, I get the following warning "Warning in if (input$country2 == "The Netherlands") { :
the condition has length > 1 and only the first element will be used "

A part of my code is below.

Thank you a lot in advance.

selectInput("country2", "Which countries would you like to see in the plot?",
choices =c("The Netherlands", "United States","Germany","India","China","Japan"), multiple = TRUE),
plotOutput("Money", click = "moneyclick1")

output$Money <- renderPlot(
if(input$country2 == "The Netherlands" && input$country2 == "Germany"){
ggplot(data = filter(survey_results_public, Country %in% c("Netherlands","Germany")), aes(WorkWeekHrs))+
geom_point(aes(y = ConvertedComp, alpha(0.7), color = Country))+

Welcome to RStudio Community!

If I a understanding things correctly, you should be able to get the data for the two inputs returned from your selectInput() in the filter() step.

For example, you would have filter(survey_results_public, Country %in% input$country2).

The issue with your if() statement has to do with the country2 input being a vector of length 2 rather than a single value. I don't think you need that step, but if you do want to test for equality in if() you'd need to pull out only one of the values in the input vector. Such as input$country2[1] == "The Netherlands"...

1 Like

Hi aosmith,

Thank you for your answer!

You're totally right, the if statement is not needed. The code is working now.

Thanks a million.

  • DaanRUG

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.