Browse Source

Map dynamique

master
Maxime Wack 7 years ago
parent
commit
d5383558bb
1 changed files with 18 additions and 7 deletions
  1. +18
    -7
      app.R

+ 18
- 7
app.R View File

@@ -75,9 +75,9 @@ server <- function(input, output, session)
{
# Create map
output$map <- renderLeaflet({
leaflet(communes, options = leafletOptions(minZoom = 6, maxZoom = 14)) %>%
leaflet(options = leafletOptions(minZoom = 6, maxZoom = 14)) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
#addPolygons(weight = 1, color = "#222222", opacity = .1, fillOpacity = .1, fillColor = "#EEEEEE") %>%
# addPolygons(weight = 1, color = "#222222", opacity = .1, fillOpacity = .1, fillColor = "#EEEEEE") %>%
setView(lat = 48.35, lng = 6, zoom = 8)
})

@@ -205,12 +205,23 @@ server <- function(input, output, session)
})

# Map
observe({
req(filteredData())

# observe({
# existing <- in_bounds()
# leafletProxy("map", data = filteredData()) %>%
# clearShapes() %>%
# })
comm <- communes
comm@data %>%
left_join(filteredData()) -> comm@data

comm <- comm[!is.na(comm$n),]

pal <- colorNumeric(palette = topo.colors(100), domain = comm$n, na.color = NA, reverse = T)

leafletProxy("map", data = comm) %>%
clearShapes() %>%
clearControls() %>%
addPolygons(weight = 1, color = "#222222", opacity = .1, fillOpacity = .3, fillColor = ~pal(n)) %>%
addLegend(position = "topleft", pal = pal, values = ~n)
})

# Use a separate observer to recreate the legend as needed.
# observe({


Loading…
Cancel
Save