trafficonese / leaflet.extras2

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras2/
GNU General Public License v3.0
85 stars 20 forks source link

addgeojsonv2 is not working with leafletproxy function #64

Closed SHIVAM2607 closed 6 months ago

SHIVAM2607 commented 8 months ago

hi

I want to update my geojson in my app but addgeojsonv2 function is not working with leafletproxy, please suggest

trafficonese commented 7 months ago

This should be an issue in this package https://github.com/trafficonese/leaflet.extras

Can you give a minimal reproducible example?

trafficonese commented 6 months ago

This seems to work:

library(shiny)  
library(leaflet)
library(leaflet.extras)

fName <- "https://rawgit.com/benbalter/dc-maps/master/maps/ward-2012.geojson"
geoJson <- jsonlite::fromJSON(readr::read_file(fName))

ui <- fluidPage(
  actionButton("act", "addgeoson"),
  leafletOutput("map")
)

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet()  %>% 
      addTiles() %>% 
      setView(-77.0369, 38.9072, 11)
  })
  observeEvent(input$act, {
    leafletProxy("map") %>% 
      addGeoJSONv2(
        jsonlite::toJSON(geoJson), weight = 1, fillOpacity = 0.6)
  })
}
shinyApp(ui, server)