【问题标题】:Shiny leaflet map reactive闪亮的传单地图反应
【发布时间】:2023-01-11 20:46:11
【问题描述】:

我正在制作一个闪亮的应用程序。我正在尝试使我的地图具有交互性,其中地图仅显示选定的站点。虽然,现在我的地图显示了数据中每个站点的位置。到目前为止,这是我尝试过的。(这是一个简化的代码)

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

【问题讨论】:

    标签: r shiny leaflet


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-10-30
      • 1970-01-01
      • 2019-09-03
      • 2021-12-30
      • 2016-12-29
      • 2018-03-13
      • 1970-01-01
      • 2016-02-22
      • 1970-01-01
      相关资源
      最近更新 更多