From d5383558bbbfa9569ed557186a270935c2c8f2d0 Mon Sep 17 00:00:00 2001 From: Maxime Wack Date: Tue, 7 Mar 2017 04:30:35 +0100 Subject: [PATCH] Map dynamique --- app.R | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app.R b/app.R index 23d3a3b..10d98ad 100644 --- a/app.R +++ b/app.R @@ -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({