|
|
@@ -69,72 +69,73 @@ ui <- bootstrapPage( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
server <- function(input, output, session) |
|
|
|
{ |
|
|
|
# Create map |
|
|
|
output$map <- renderLeaflet({ |
|
|
|
leaflet(communes, options = leafletOptions(minZoom = 7, maxZoom = 15)) %>% |
|
|
|
addProviderTiles(providers$CartoDB.Positron) %>% |
|
|
|
addPolygons(weight = 1, color = "#222222", opacity = .1, fillOpacity = .1, fillColor = "#EEEEEE") %>% |
|
|
|
setView(lat = 48.35, lng = 6, zoom = 9) |
|
|
|
}) |
|
|
|
# Filter in bounds |
|
|
|
in_bounds <- reactive({ |
|
|
|
if (is.null(input$map_bounds)) |
|
|
|
return(communes[F,]) |
|
|
|
bounds <- input$map_bounds |
|
|
|
latrng <- range(bounds$north, bounds$south) |
|
|
|
lngrng <- range(bounds$east, bounds$west) |
|
|
|
communes[lats >= latrng[1] & lats <= latrng[2] & lngs >= lngrng[1] & lngs <= lngrng[2],] |
|
|
|
}) |
|
|
|
# Filter GHM |
|
|
|
# filteredData <- reactive({ |
|
|
|
# GHM %>% |
|
|
|
# filter(Sexe %in% input$check_sexe, |
|
|
|
# Age <= input$slider_age[2] & Age >= input$slider_age[1], |
|
|
|
# GHM %in% input$choice_ghm, |
|
|
|
# date_entree <= input$slider_date[2] & date_sortie >= input$slider_date[1], |
|
|
|
# CP %in% in_bounds$insee) |
|
|
|
# }) |
|
|
|
# Plots |
|
|
|
# observe({ |
|
|
|
# output$plot_sexe <- renderPlotly({ |
|
|
|
# filteredData() %>% |
|
|
|
# ( |
|
|
|
# ggplot() + |
|
|
|
# aes(x = Sexe) + |
|
|
|
# geom_bar(position = "stacked") |
|
|
|
# ) %>% ggplotly |
|
|
|
# }) |
|
|
|
# }) |
|
|
|
# observe({ |
|
|
|
# output$plot_age <- renderPlotly({ |
|
|
|
# filteredData() %>% |
|
|
|
# ( |
|
|
|
# ggplot() + |
|
|
|
# aes(x = Age, y = ..density..) + |
|
|
|
# geom_histogram() + |
|
|
|
# geom_density() |
|
|
|
# ) %>% ggplotly |
|
|
|
# }) |
|
|
|
# }) |
|
|
|
# observe({ |
|
|
|
# leafletProxy("map", data = in_bounds()) %>% |
|
|
|
# clearShapes() %>% |
|
|
|
# }) |
|
|
|
# Use a separate observer to recreate the legend as needed. |
|
|
|
# observe({ |
|
|
|
# Remove any existing legend, and only if the legend is |
|
|
|
# enabled, create a new one. |
|
|
|
# leafletProxy("map", data = quakes) %>% |
|
|
|
# clearControls() |
|
|
|
# if (input$legend) { |
|
|
|
# pal <- colorpal() |
|
|
|
# proxy %>% addLegend(position = "bottomright", |
|
|
|
# pal = pal, values = ~mag |
|
|
|
# ) |
|
|
|
# } |
|
|
|
# }) |
|
|
|
} |
|
|
|
# Server ---- |
|
|
|
server <- function(input, output, session) |
|
|
|
{ |
|
|
|
# Create map |
|
|
|
output$map <- renderLeaflet({ |
|
|
|
leaflet(communes, options = leafletOptions(minZoom = 6, maxZoom = 14)) %>% |
|
|
|
addProviderTiles(providers$CartoDB.Positron) %>% |
|
|
|
#addPolygons(weight = 1, color = "#222222", opacity = .1, fillOpacity = .1, fillColor = "#EEEEEE") %>% |
|
|
|
setView(lat = 48.35, lng = 6, zoom = 8) |
|
|
|
}) |
|
|
|
# Filter in bounds |
|
|
|
in_bounds <- reactive({ |
|
|
|
if (is.null(input$map_bounds)) |
|
|
|
return(communes[F,]) |
|
|
|
bounds <- input$map_bounds |
|
|
|
latrng <- range(bounds$north, bounds$south) |
|
|
|
lngrng <- range(bounds$east, bounds$west) |
|
|
|
communes[lats >= latrng[1] & lats <= latrng[2] & lngs >= lngrng[1] & lngs <= lngrng[2],] |
|
|
|
}) |
|
|
|
# Filter GHM |
|
|
|
# filteredData <- reactive({ |
|
|
|
# GHM %>% |
|
|
|
# filter(Sexe %in% input$check_sexe, |
|
|
|
# Age <= input$slider_age[2] & Age >= input$slider_age[1], |
|
|
|
# GHM %in% input$choice_ghm, |
|
|
|
# date_entree <= input$slider_date[2] & date_sortie >= input$slider_date[1], |
|
|
|
# CP %in% in_bounds$insee) |
|
|
|
# }) |
|
|
|
# Plots |
|
|
|
# observe({ |
|
|
|
# output$plot_sexe <- renderPlotly({ |
|
|
|
# filteredData() %>% |
|
|
|
# ( |
|
|
|
# ggplot() + |
|
|
|
# aes(x = Sexe) + |
|
|
|
# geom_bar(position = "stacked") |
|
|
|
# ) %>% ggplotly |
|
|
|
# }) |
|
|
|
# }) |
|
|
|
# observe({ |
|
|
|
# output$plot_age <- renderPlotly({ |
|
|
|
# filteredData() %>% |
|
|
|
# ( |
|
|
|
# ggplot() + |
|
|
|
# aes(x = Age, y = ..density..) + |
|
|
|
# geom_histogram() + |
|
|
|
# geom_density() |
|
|
|
# ) %>% ggplotly |
|
|
|
# }) |
|
|
|
# }) |
|
|
|
# observe({ |
|
|
|
# leafletProxy("map", data = in_bounds()) %>% |
|
|
|
# clearShapes() %>% |
|
|
|
# }) |
|
|
|
# Use a separate observer to recreate the legend as needed. |
|
|
|
# observe({ |
|
|
|
# Remove any existing legend, and only if the legend is |
|
|
|
# enabled, create a new one. |
|
|
|
# leafletProxy("map", data = quakes) %>% |
|
|
|
# clearControls() |
|
|
|
# if (input$legend) { |
|
|
|
# pal <- colorpal() |
|
|
|
# proxy %>% addLegend(position = "bottomright", |
|
|
|
# pal = pal, values = ~mag |
|
|
|
# ) |
|
|
|
# } |
|
|
|
# }) |
|
|
|
} |
|
|
|
|
|
|
|
shinyApp(ui = ui, server = server) |