通过 R Flexdashboard 中的输入选择过滤传单标记

Filter Leaflet markers by input selection in R Flexdashboard

我正在尝试根据在用户定义的日期范围内选择的内容过滤在 Leaflet 地图上绘制的标记。以下代码返回无法找到 hfxLoc 对象的错误。我使用了以下方法(在其他元素(即 renderPlot、renderValueBox 等)的 render 函数内进行过滤)。我的过滤方法是否正确,或者它是否需要发生在Leaflet 代码块中的不同位置?

inputSelect代码如下:

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

传单代码如下:

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())

您可以从 leaflet 中删除 data = hfxLoc,因为您已经从 filter 结果中输入过滤后的数据。管道输入的结果数据将被假定为 leaflet.

中的第一个参数 data
renderLeaflet({
  hfxLoc <- hfxETA %>%
    dplyr::filter(as.Date(eta_date) >= input$dateRange[1] & as.Date(eta_date) <=  input$dateRange[2]) %>%
    leaflet() %>%
    ...