观察到不响应用户输入

时间:2018-08-16 07:41:19

标签: r shiny leaflet

我想根据用户输入对多边形进行颜色映射。问题是观察功能没有响应用户输入。这里是形状文件m1.shp。整个应用程序是here我的问题是关于如何包括反应性,以便用户选择时输入$区域,将弹出选择的多边形并进行颜色映射。代码:

#user
#loading shape file
mp<-readOGR(
  dsn="C:\\merge",
  layer="m1")
#select input
selectInput(inputId = "area", 
                                     label = " AreaType:",
                                     choices = c(
                                       "All",
                                       unique(as.character(mp$AreaTyp))
                                     )
#server   
 #INTERACTIVE MAPPING
      #colorfunction
      pal<-colorFactor(rainbow(7),mp$AreaTyp)

      #set data based on user input
      fdata<-reactive({
        data<-mp
        if(input$area!="All"){
          data<-data[data$AreaType==input$area,]
        }
        data
      })



      output$leaf<-renderLeaflet({

        leaflet(fdata()) %>%

          #Initializing the map
          setView(lng=36.092245, lat=-00.292115,zoom=15)%>%

          #Base map
          #Add default OpenStreetMap map tiles
          addTiles(group = "default")%>%
          #addProviderTiles("Esri.NatGeoWorldMap",group = "default")%>%  
          #addProviderTiles("CartoDB.Positron",group = "custom")%>%

          #Overlay map
          addPolygons(
            data = fdata(),
            fillColor = "blue",
            weight = 1, smoothFactor = 0.5,
            opacity = 1.0, fillOpacity = 1.0,
            group = "basepoly",
            highlightOptions = highlightOptions(
              weight = 2,
              color = "red",
              fillOpacity = 0.7,
              bringToFront = TRUE
            ),label =~LIA


          )


      })


      observe({

        leafletProxy("leaf",data = fdata()) %>%


          clearShapes() %>%
          addPolygons(
            weight = 1, smoothFactor = 0.5,
            opacity = 1.0, fillOpacity = 1.0,
            data=fdata(),
            fillColor = ~pal(AreaTyp),
            label =~LIA

          )



      })

0 个答案:

没有答案