0

i am trying to make a graph about child mortality, it works fine when i select just one country but it seems to exclude data points when i select multiple countries, i have included 2 images to show the problem. mdg1a is the data set containing the info for all years, all regions, all countriesthis is how it looks for 1 country Here you see the NA when selecting 2 countries

  cir <- reactive({
    #cir stands for Countries In Region
    if (is.null(input$regionInput)) {
      return(NULL)
    }
    if (input$regionInput == "All") {
      mdg1a
    } else {
      mdg1a %>%
        filter(region == input$regionInput)
    }
  })

  output$countryOutput <- renderUI({
    selectInput("countryInput", "country",
                sort(unique(cir()$country)),
                multiple = TRUE,
                selected = "")
  })


  filtered <- reactive({
    if (is.null(input$regionInput)) {
      return(NULL)
    }
    if (is.null(input$countryInput)) {
      return(NULL)
    }
    cir() %>%
    filter(year >= input$yearInput[1],
           year <= input$yearInput[2],
           country == input$countryInput)
  })
Chiel
  • 1
  • 1
    If I'm understanding correctly--can't run it myself without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)--`input$countryInput` is a vector of 1 or more country names. So to check that each country is *among* those selected, not *equal to* those selected, you need `%in%`, not `==` – camille Dec 01 '18 at 20:49
  • thank, the solution works. I didnt submit all the code because it might cause problems regarding plagiarism for my assignment. – Chiel Dec 02 '18 at 22:26
  • You don't have to use the exact code from your assignment—you can always come up with ways to make an example or use an example that comes with a package that will replicate the issue – camille Dec 03 '18 at 03:50

0 Answers0