Skip to content
Snippets Groups Projects
Commit 20b6ee6c authored by ronan.vignard's avatar ronan.vignard
Browse files

Partially fix issue #32

parent 859ece68
No related branches found
No related tags found
2 merge requests!81Ajout d'un sélecteur de dates pour la production,!79Fix issue #32
......@@ -145,5 +145,5 @@ carriere$code_ape <- as.factor(carriere$code_ape)
production_carriere$annee <- as.factor(production_carriere$annee)
# Variables
year_production <- '2020'
year_administrative <- '2020'
# year_production <- '2020'
year_administrative <- '2020'
\ No newline at end of file
......@@ -14,8 +14,9 @@ shinyServer(function(input, output) {
production_date <- format(max(production_carriere$date_export, na.rm=TRUE), "%d/%m/%Y")
administrative_date <- format(max(carriere$date_export, na.rm=TRUE), "%d/%m/%Y")
output$production_date <- renderText({
paste("Données de production ", year_production ," actualisées au ", production_date,
" - Données administratives ", year_administrative ," actualisées au ", administrative_date)})
paste("Données de production ", input$select_year ," actualisées au ", production_date,
" - Données administratives ", year_administrative ," actualisées au ", administrative_date)
})
# Génération des titres réactifs par territoire
nom_departement <- reactive({ departements %>% filter(code_departement == input$select_dpt) %>% select(nom_departement) })
......@@ -28,29 +29,32 @@ shinyServer(function(input, output) {
if(input$select_dpt == "r52") { paste("Liste des carrières en Pays de la Loire") }
else { paste("Liste des carrières en ", nom_departement()) }
})
output$title_production_departement <- renderText({
paste0("Production totale par département en ",input$select_year)
})
output$title_nb_type_roche <- renderText({
if(input$select_dpt == "r52") { paste("Nombre de carrières en fonctionnement par type de carrière en Pays de la Loire") }
else { paste("Nombre de carrières en fonctionnement par type de carrière en ", nom_departement()) }
})
output$title_production_type_roche <- renderText({
if(input$select_dpt == "r52") { paste("Production totale par type de carrière en", year_production, "en Pays de la Loire") }
else { paste("Production totale par type de carrière en ", year_production, " en ", nom_departement()) }
if(input$select_dpt == "r52") { paste("Production totale par type de carrière en", input$select_year, "en Pays de la Loire") }
else { paste("Production totale par type de carrière en ", input$select_year, " en ", nom_departement()) }
})
output$title_nb_type_ressource <- renderText({
if(input$select_dpt == "r52") { paste("Nombre de carrières en fonctionnement par type de ressource en Pays de la Loire") }
else { paste("Nombre de carrières en fonctionnement par type de ressource en ", nom_departement()) }
})
output$title_production_type_ressource <- renderText({
if(input$select_dpt == "r52") { paste("Production totale par type de ressource en", year_production, "en Pays de la Loire") }
else { paste("Production totale par type de ressource en ", year_production, " en ", nom_departement()) }
if(input$select_dpt == "r52") { paste("Production totale par type de ressource en", input$select_year, "en Pays de la Loire") }
else { paste("Production totale par type de ressource en ", input$select_year, " en ", nom_departement()) }
})
output$title_nb_nom_substance <- renderText({
if(input$select_dpt == "r52") { paste("Nombre de carrières en fonctionnement par type de substance en Pays de la Loire") }
else { paste("Nombre de carrières en fonctionnement par type de substance en ", nom_departement()) }
})
output$title_production_nom_substance <- renderText({
if(input$select_dpt == "r52") { paste("Production totale par type de substance en", year_production, "en Pays de la Loire") }
else { paste("Production totale par type de substance en ", year_production, " en ", nom_departement()) }
if(input$select_dpt == "r52") { paste("Production totale par type de substance en", input$select_year, "en Pays de la Loire") }
else { paste("Production totale par type de substance en ", input$select_year, " en ", nom_departement()) }
})
output$title_production <- renderText({
if(input$select_dpt == "r52") { paste("Évolution de la production en Pays de la Loire") }
......@@ -80,16 +84,15 @@ shinyServer(function(input, output) {
})
#Production totale de l'année
total_production <- production_carriere %>% filter(annee == year_production) %>% dplyr::summarise(total = sum(production, na.rm=TRUE))
total_production_dpt <- reactive ({ production_dpt() %>% filter(annee == year_production) %>% dplyr::summarise(total = sum(production, na.rm=TRUE)) })
output$totalProduction <- renderUI({ infoBox(icon = icon("cogs"), color = "purple",
value = tags$p(
if (input$select_dpt == "r52") { total_production$total/1000000 }
else { total_production_dpt()$total/1000000 }, style = "font-size: 150%;"),
title = tags$p(paste("Production totale de l'année ", year_production, " (en Mt)"),
style = "font-size: 100%;"),
width = 12
)
total_production <- reactive ({ production_carriere %>% filter(annee == input$select_year) %>% dplyr::summarise(total = sum(production, na.rm=TRUE)) })
total_production_dpt <- reactive ({ production_dpt() %>% filter(annee == input$select_year) %>% dplyr::summarise(total = sum(production, na.rm=TRUE)) })
output$totalProduction <- renderUI({
infoBox(icon = icon("cogs"), color = "purple",
value = tags$p(
if (input$select_dpt == "r52") { total_production()$total/1000000 }
else { total_production_dpt()$total/1000000 }, style = "font-size: 150%;"),
title = tags$p(paste("Production totale de l'année ", input$select_year, " (en Mt)"),
style = "font-size: 100%;"), width = 12)
})
#Nombre de carrières par type de carrière
......@@ -107,8 +110,8 @@ shinyServer(function(input, output) {
# select(annee, production, type_roche) %>% group_by(annee,type_roche) %>%
# dplyr::summarise(prod = sum(production, na.rm=TRUE)) })
# #Répartition de la production par type de carrière sur un millésime
# prod_year_production_type_roche <- prod_by_year_type_roche %>% filter(annee == year_production)
# prod_year_production_type_roche_dpt <- reactive ({ prod_by_year_type_roche_dpt() %>% filter(annee == year_production) })
# prod_year_production_type_roche <- prod_by_year_type_roche %>% filter(annee == input$select_year)
# prod_year_production_type_roche_dpt <- reactive ({ prod_by_year_type_roche_dpt() %>% filter(annee == input$select_year) })
output$nbCarriereRochesMassives <- renderUI({
infoBox(icon = icon("diamond"), color = "purple",
......@@ -341,14 +344,14 @@ shinyServer(function(input, output) {
dplyr::summarise(prod = sum(production, na.rm=TRUE))
# Calcul de répartition de la production par département en year_production
prod_year_production_dep <- prod_by_year_dep %>% filter(annee == year_production) %>%
mutate(percent = scales::percent(prod / sum(prod)))
prod_year_production_dep <- reactive({ prod_by_year_dep %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) })
# Production totale par département en year_production
prod_year_production_dep <- prod_by_year_dep %>% filter(annee == year_production) %>%
mutate(percent = scales::percent(prod / sum(prod)))
prod_year_production_dep <- reactive ({ prod_by_year_dep %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) })
output$chart_prod_by_year_dep <- renderHighchart({
chart_prod_by_year_dep <- prod_year_production_dep %>%
chart_prod_by_year_dep <- prod_year_production_dep() %>%
hchart("pie", hcaes(x = nom_departement, y = prod)) %>%
hc_tooltip(headerFormat = "",pointFormat = "<b>{point.percent}</b>") %>%
hc_add_theme(hc_theme_smpl()) %>%
......@@ -385,14 +388,14 @@ shinyServer(function(input, output) {
dplyr::summarise(prod = sum(production, na.rm=TRUE)) })
# Calcul de la répartition de la production par type de carrière en year_production
prod_year_production_type_roche <- prod_by_year_type_roche %>% filter(annee == year_production) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na()
prod_year_production_type_roche_dpt <- reactive ({ prod_by_year_type_roche_dpt() %>% filter(annee == year_production) %>%
prod_year_production_type_roche <- reactive ({ prod_by_year_type_roche %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na() })
prod_year_production_type_roche_dpt <- reactive ({ prod_by_year_type_roche_dpt() %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na() })
# Production par type de carrière en year_production
output$chart_prod_by_year_type_roche <- renderHighchart({
if (input$select_dpt == "r52") { prod_year_production_type_roche <- prod_year_production_type_roche }
if (input$select_dpt == "r52") { prod_year_production_type_roche <- prod_year_production_type_roche() }
else { prod_year_production_type_roche <- prod_year_production_type_roche_dpt() }
chart_prod_by_year_type_roche <- prod_year_production_type_roche %>%
hchart("pie", hcaes(x = type_roche, y = prod)) %>%
......@@ -430,14 +433,14 @@ shinyServer(function(input, output) {
select(annee, production, type_ressource) %>% group_by(annee,type_ressource) %>% dplyr::summarise(prod = sum(production, na.rm=TRUE)) })
# Calcul de la répartition de la production par type de ressource en year_production
prod_year_production_type_ressource <- prod_by_year_type_ressource %>% filter(annee == year_production) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na()
prod_year_production_type_ressource_dpt <- reactive ({ prod_by_year_type_ressource_dpt() %>% filter(annee == year_production) %>%
prod_year_production_type_ressource <- reactive ({ prod_by_year_type_ressource %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na() })
prod_year_production_type_ressource_dpt <- reactive ({ prod_by_year_type_ressource_dpt() %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na() })
# Production par type de ressource en year_production
output$chart_prod_by_year_type_ressource <- renderHighchart({
if (input$select_dpt == "r52") { prod_year_production_type_ressource <- prod_year_production_type_ressource }
if (input$select_dpt == "r52") { prod_year_production_type_ressource <- prod_year_production_type_ressource() }
else { prod_year_production_type_ressource <- prod_year_production_type_ressource_dpt() }
chart_prod_by_year_type_ressource <- prod_year_production_type_ressource %>%
hchart("pie", hcaes(x = type_ressource, y = prod)) %>%
......@@ -476,14 +479,14 @@ shinyServer(function(input, output) {
select(annee, production, nom_substance) %>% group_by(annee,nom_substance) %>% dplyr::summarise(prod = sum(production, na.rm=TRUE)) })
# Calcul de la répartition de la production par type de substance en year_production
prod_year_production_nom_substance <- prod_by_year_nom_substance %>% filter(annee == year_production) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na()
prod_year_production_nom_substance_dpt <- reactive ({ prod_by_year_nom_substance_dpt() %>% filter(annee == year_production) %>%
prod_year_production_nom_substance <- reactive({ prod_by_year_nom_substance %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na() })
prod_year_production_nom_substance_dpt <- reactive ({ prod_by_year_nom_substance_dpt() %>% filter(annee == input$select_year) %>%
mutate(percent = scales::percent(prod / sum(prod))) %>% drop_na() })
# Production par type de substance en year_production
output$chart_prod_by_year_nom_substance <- renderHighchart({
if (input$select_dpt == "r52") { prod_year_production_nom_substance <- prod_year_production_nom_substance }
if (input$select_dpt == "r52") { prod_year_production_nom_substance <- prod_year_production_nom_substance() }
else { prod_year_production_nom_substance <- prod_year_production_nom_substance_dpt() }
chart_prod_by_year_nom_substance <- prod_year_production_nom_substance %>%
hchart("pie", hcaes(x = nom_substance, y = prod)) %>%
......@@ -738,19 +741,19 @@ shinyServer(function(input, output) {
})
# Par production
production_geom <- carriere_geom %>% left_join(production_carriere, by = "code_etablissement") %>% filter(annee == year_production) %>%
select(code_departement = code_departement.x, code_etablissement, nom_commune, annee, nom_etablissement, production, the_geom)
production_geom <- reactive({ carriere_geom %>% left_join(production_carriere, by = "code_etablissement") %>% filter(annee == input$select_year) %>%
select(code_departement = code_departement.x, code_etablissement, nom_commune, annee, nom_etablissement, production, the_geom) })
output$production_map <- renderLeaflet({
binpal <- colorBin("Dark2", production_geom$production, 8, pretty = TRUE)
binpal <- colorBin("Dark2", production_geom()$production, 8, pretty = TRUE)
if (input$select_dpt == "r52") {
production_map <- leaflet(production_geom) %>%
production_map <- leaflet(production_geom()) %>%
setView(lng = -0.55, lat = 47.4667, zoom = 8) %>%
addTiles(attribution = credits_maps) %>%
addMarkers(popup = paste("<h5>",production_geom$nom_etablissement,"</h5>",
"<strong>Code l'établissement :</strong> ",production_geom$code_etablissement,
"<br /><strong>Commune :</strong> ",production_geom$nom_commune,
"<br /><strong>Production ",year_production," :</strong> ",production_geom$production," tonnes"), icon = customIcon) %>%
addMarkers(popup = paste("<h5>",production_geom()$nom_etablissement,"</h5>",
"<strong>Code l'établissement :</strong> ",production_geom()$code_etablissement,
"<br /><strong>Commune :</strong> ",production_geom()$nom_commune,
"<br /><strong>Production ",input$select_year," :</strong> ",production_geom()$production," tonnes"), icon = customIcon) %>%
addCircles(color = ~binpal(production),
weight = 1,
opacity = 1,
......@@ -759,17 +762,17 @@ shinyServer(function(input, output) {
addPolygons(data = departement_geom, opacity = 0.3, fillOpacity = 0.1) %>%
addPolygons(data = region, opacity = 0.3, fillOpacity = 0) %>%
addFullscreenControl() %>%
addLegend("bottomright", pal = binpal, values = production_geom$production, title = paste("Production ",year_production," (en tonnes)"), opacity = 0.8)
addLegend("bottomright", pal = binpal, values = production_geom()$production, title = paste("Production ",input$select_year," (en tonnes)"), opacity = 0.8)
} else {
departement_geom_selected <- departement_geom %>% filter(insee_dep == input$select_dpt)
production_geom_selected <- production_geom %>% filter(code_departement == input$select_dpt)
production_map <- leaflet(production_geom_selected) %>%
production_geom_selected <- production_geom() %>% filter(code_departement == input$select_dpt)
production_map <- leaflet(production_geom_selected()) %>%
clearBounds() %>%
addTiles(attribution = credits_maps) %>%
addMarkers(popup = paste("<h5>",production_geom_selected$nom_etablissement,"</h5>",
"<br /><strong>Code l'établissement :</strong> ",production_geom_selected$code_etablissement,
"<br /><strong>Commune :</strong> ",production_geom_selected$nom_commune,
"<br /><strong>Production ",year_production," :</strong> ",production_geom_selected$production," tonnes"), icon = customIcon) %>%
addMarkers(popup = paste("<h5>",production_geom_selected()$nom_etablissement,"</h5>",
"<br /><strong>Code l'établissement :</strong> ",production_geom_selected()$code_etablissement,
"<br /><strong>Commune :</strong> ",production_geom_selected()$nom_commune,
"<br /><strong>Production ",input$select_year," :</strong> ",production_geom_selected()$production," tonnes"), icon = customIcon) %>%
addCircles(color = ~binpal(production),
weight = 1,
opacity = 1,
......@@ -777,7 +780,7 @@ shinyServer(function(input, output) {
radius = ~sqrt(production) * 8) %>%
addPolygons(data = departement_geom_selected, opacity = 0.5, fillOpacity = 0) %>%
addFullscreenControl() %>%
addLegend("bottomright", pal = binpal, values = production_geom_selected$production, title = paste("Production ",year_production," (en tonnes)"), opacity = 0.8)
addLegend("bottomright", pal = binpal, values = production_geom_selected()$production, title = paste("Production ",input$select_year," (en tonnes)"), opacity = 0.8)
}
})
})
......@@ -10,7 +10,6 @@
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Accueil", tabName = "home", icon = icon('home')),
#selectInput("select_year","Année :",c(year(today()):2016),selected=year(today())),
selectInput("select_dpt","Territoire :",choices = list(
Région = c("Pays de la Loire" = "r52"),
Départements = c("Loire-Atlantique" = "44",
......@@ -18,6 +17,7 @@ sidebar <- dashboardSidebar(
"Mayenne" = "53",
"Sarthe" = "72",
"Vendée" = "85")),selected = "r52"),
selectInput("select_year","Année de production :",c(2020:2016),selected="2020"),
menuItem('Liste des carrières', tabName = 'lists', icon = icon('table')),
menuItem('Statistiques', tabName = 'indicators', icon = icon('bar-chart'),
menuSubItem('Graphiques et tableaux', tabName = 'graphics'),
......@@ -83,7 +83,8 @@ body <- dashboardBody(
box(h3("Nombre de carrières en fonctionnement par département en Pays de la Loire"),
highchartOutput('graph_carriere_departement'),br(),
tableOutput('tab_carriere_departement')),
box(h3(paste0("Production totale par département en ",year_production)),
box(h3(textOutput("title_production_departement")),
# box(h3(paste0("Production totale par département en ",input$select_year)),
highchartOutput('chart_prod_by_year_dep'))
))),
tabPanel("Types de carrière",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment