r语言 - 闪亮的小叶图反应性



我在制作一个闪亮的应用程序的过程中。我试图使我的地图互动,地图只显示选定的网站。虽然,现在我的地图显示的是数据中每个站点的位置。这是我到目前为止一直在做的事情。(这是一个简化的代码)

Site_Name <-sample(c('a','b','c'),replace=T,5)
Latitude <-runif(5,min=-26, max=-22)
Longitude<-runif(5,min=-54, max=-48)
Sites <-data.frame(Site_Name,Latitude,Longitude)

fluidPage(
theme = shinytheme("cerulean"),
sidebarLayout(
sidebarPanel(
selectizeInput("sites",
"Site Name",choices= Sites$Site_Name,
options= list(maxItems = 2)),

mainPanel(
tabsetPanel(
tabPanel("Plots",leafletOutput("Station")
)
)
shinyServer(function(input, output, session) {
df1 <- eventReactive(input$sites, {
Sites %>% dplyr::filter(Site_Name %in% input$sites)
})

output$Station = renderLeaflet({
leaflet(data = df1()) %>%
addProviderTiles(providers$Esri.WorldStreetMap) %>%
addMarkers(Sites$Longitude, Sites$Latitude, popup= input$sites,
icon = list(
iconUrl = 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
iconSize = c(13, 20)))
})
}

它显示了所有内容,因为你让它显示所有内容。您应该将addMarkers中的Sites$Longitude, Sites$Latitude, popup= input$sites替换为lng = ~Longitude, lat = ~Latitude, popup= ~Site_Name

最新更新