rstudio / shinydashboard

Shiny Dashboarding framework
https://rstudio.github.io/shinydashboard/
Other
892 stars 300 forks source link

SelectInput not working to update leaflet markers #253

Open sambitnandi opened 6 years ago

sambitnandi commented 6 years ago

I have created a shiny dashboard and on the user selection from the drop the dropdown I want to filter a dataset and plot the filtered IDs on the map. However the UI input is not changing anything in the dashboard. Below is my code.

Any help is appreciated. I am stuck here for a while now.

`server <- function(input, output, session) {

  output$MapPlot1 <- renderLeaflet({
    leaflet(data = NodeList) %>% setView(-98.35, 39.7,zoom = 5) %>%
      addTiles() %>%
      addCircleMarkers(~Longitude,~Lattitude,popup = ~as.character(hcp_cust_name),
                       color= ~pal(specdesc),
                       stroke = FALSE,
                       fillOpacity = 1,
                       layerId = ~hcp_az_cust_id)
  })

  observe({

    valtarget <- input$target
    valpriority <- input$priority
    valspec <- input$spec
    valaff <- input$aff
    valuniv <- input$universe
    valinf <- input$influence

    print(valtarget)

      if (valtarget == "ALL"){
        targetinp <- c('TARGET', 'NON-TARGET')
      } else{
        targetinp <- valtarget
      }

      if (valpriority== "ALL"){
        priorityinp <- c('HIGH', 'MED', 'LOW')
      } else{
        priorityinp <- valpriority
      }

      if (valspec == "ALL"){
        specinp <- c('RAD-ONC', 'MED-ONC', 'OTHER')
      } else{
        specinp <- valspec
      }

      if (valaff == "ALL"){
        affinp <- c('ACADEMIC', 'COMMUNITY', 'UNK')
      } else{
        affinp <- valaff
      }

      if (valuniv == "NSCLC"){
        universeinp <- c('NSCLC', 'STAGE 3')
      } else{
        universeinp <- valuniv
      }

      if (valinf == "Show All"){
        influenceinp <- c('YES', 'NO')
      } else{
        influenceinp <- "YES"
      }

      datasetInput <- subset(NodeList, influencer %in% influenceinp
                           & s3_flg %in% universeinp
                           & target %in% targetinp
                           & account_classification %in% affinp
                           & specdesc %in% specinp
                           & priority %in% priorityinp)

        leafletProxy("MapPlot1", session) %>% clearMarkers() %>%
          addCircleMarkers(lng = datasetInput$Longitude,
                           lat = datasetInput$Lattitude)
      })

}
`