[英]Shiny leaflet map reactive
我正在制作一個 shiny 應用程序。 我正在嘗試使我的 map 具有交互性,其中 map 僅顯示選定的站點。 雖然,現在我的 map 正在顯示數據中每個站點的位置。 到目前為止,這是我嘗試過的。(這是一個簡化的代碼)
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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.