我正在使用闪亮的传单地图,并希望允许用户在边栏中选择多条公交路线。由于要选择/取消选择所有功能,因此我想使用pickerInput()。但是,全部取消选择功能在我的代码中不起作用。
基于这个问题pickerInput Not Clearing All Choices,我试图在我对observeEvent()的调用中添加一条if / else语句。这对我的代码没有任何明显的影响。
library(shiny)
library(sf)
library(tidyverse)
library(leaflet)
library(shiny)
library(sp)
library(rsconnect)
library(shinyWidgets)
routes <- st_read(dsn = "data/MetroTransitData183.gdb",
layer = "transitroute", stringsAsFactors= FALSE) %>% st_transform(., crs = 4326)
ui <- fluidPage(
# Application title
titlePanel("RKAAMP Priorty Tract Travelshed Viewer"),
sidebarLayout(
sidebarPanel(
pickerInput("routes",
"Select Routes by Route Number:",
choices = as.list(routes$ROUTE_NUM),
multiple = TRUE,
options= pickerOptions(actionsBox = TRUE),
width = "75%"
)
)
)
)
server <- function(input, output, session) {
select_routes <- reactive({
routes %>% filter(routes$ROUTE_NUM %in% input$routes)
})
output$travelshed_map <- renderLeaflet({
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
setView(lng = -122.217064, lat = 47.482880, zoom = 11 )
})
observeEvent(input$routes, {
proxy <- leafletProxy("travelshed_map")
if(!is.null(input$routes) && routes$ROUTE_NUM %in% input$routes) {
proxy %>%
addPolylines(data= select_routes(), color = "Black", weight = 2,
opacity = 0.3, group = "routes" )
} else {
proxy %>% clearGroup("routes")
}
}, ignoreNULL = TRUE)
}
我希望用户能够选择“全部”并返回所有路线或通过特定的路线号进行选择。还需要一种从地图上删除路线的方法。