在this tutorial之后,我尝试使用leaflet.extras包在我的闪亮应用程序中向我的传单地图添加搜索框。该示例使用静态数据,我想使用反应性数据按SITE_ID列搜索点。问题出在“组”和“ targetGroups”中,并从反应性数据中选择字段。
#### instead of 'cities' in the example it would be reactive e.g. df()$SITE_ID #####
cities <- read.csv(textConnection("
City,Lat,Long,Pop
Boston,42.3601,-71.0589,645966
Hartford,41.7627,-72.6743,125017
New York City,40.7127,-74.0059,8406000
Philadelphia,39.9500,-75.1667,1553000
Pittsburgh,40.4397,-79.9764,305841
Providence,41.8236,-71.4222,177994
"))
leaflet(cities) %>% addProviderTiles(providers$OpenStreetMap) %>%
addCircleMarkers(lng = ~Long, lat = ~Lat, weight = 1, fillOpacity=0.5,
radius = ~sqrt(Pop)/50 , popup = ~City, label=~City, group
='cities') %>%
addResetMapButton() %>%
addSearchFeatures(
targetGroups = 'cities',
options = searchFeaturesOptions(
zoom=12, openPopup = TRUE, firstTipSubmit = TRUE,
autoCollapse = TRUE, hideMarkerOnCollapse = TRUE ))