In shiny + leaflet, setview is updated every time render is executed. I want to prevent this

﹥>﹥吖頭↗ 提交于 2020-05-15 08:13:50

问题


I create a map app using shiny and leaflet. It projects a map and some shape files. The shape file has area values. I want to set whether to display the shape file or not based on the area value. Specifically, the sliderInput function is used.

Although the display of the shape file is restricted using the sliderInput function, The setview is reset every time the number is changed by sliderInput. Instead of running setview every time, I want you to run setview where you are. What should I do? I want you to tell me.

Below is the sample code

library(shiny)
library(leaflet)

ui <- shinyUI(fluidPage(
  titlePanel("sample sample sample sample "),

  #sidebarLayout settings
  sidebarLayout(
    sidebarPanel(
      sliderInput("area_slider",label = h3("settings"),min = 0,max = 6000,value = c(0,6000)),
    ),
    #mainpanel settings
    mainPanel(
      leafletOutput("mymap",height=600)
    )
  )
))

server <- shinyServer(function(input, output) {

  #map settings
  output$mymap <- renderLeaflet({
    leaflet() %>% 

      addTiles(group="OSM")%>%

      #setView
      #setView(lng=139.8,lat=35.7,zoom=12)%>%

      #maker settings1
      addAwesomeMarkers(lng = df$lng,
                        lat = df$lat,
                        clusterOptions = markerClusterOptions(),
                        group="Oct")%>%


      addPolygons(data = shp %>% subset(shp@data$area < input$area_slider),
                  color = "#2feeb5",
                  group="carea")%>%

      #Layers Control
      addLayersControl(
        baseGroups = c("OSM"),
        overlayGroups = c("Oct","carea"),
        options = layersControlOptions(collapsed = FALSE))

  })
})

shinyApp(ui, server)

来源:https://stackoverflow.com/questions/61010890/in-shiny-leaflet-setview-is-updated-every-time-render-is-executed-i-want-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!