TransWikia.com

Filter Leaflet markers by input selectionin R Flexdashboard

Geographic Information Systems Asked by Ryan Garnett on December 9, 2020

I am trying to filter the markers that are drawn on a Leaflet map based on what is selected in a user defined date range. The below codes is returning an error that it is unable to find hfxLoc object. I have used the below approach (filtering within the render function in other elements (i.e. renderPlot, renderValueBox, etc.). Is my approach to filtering correct, or does it need to occur in a different place in the Leaflet code block?

The inputSelect code is as follows:

selectizeInput("shiptypeInput", "Vessel type: ", choices = hfxVessels, selected = "Cargo ships", multiple = TRUE)

The leaflet code is as follows:

renderLeaflet({
  hfxLoc <- hfxETA %>%
    dplyr::filter(as.Date(eta_date) >= input$dateRange[1] & as.Date(eta_date) <=  input$dateRange[2]) %>%
  leaflet(data = hfxLoc) %>% 
  setView(lng = -60.25, lat = 46, zoom = 6) %>%
  addProviderTiles(providers$CartoDB.Positron,
                   options = providerTileOptions(minZoom = 2, maxZoom = 16)) %>%
  addMarkers(lng = ~lon, lat = ~lat, clusterOptions = markerClusterOptions())

One Answer

The issue has been resolved. The data was being based to leaflet leaflet(data = hfxETA) which was overwriting the filter. Removing the data from the leaflet call fixed the issue.

Answered by Ryan Garnett on December 9, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP