Skip to content
Snippets Groups Projects
Commit c3a9e93a authored by Franck.Gaspard's avatar Franck.Gaspard
Browse files

complétude du module de visualisation de la page ESU et recherche de comment...

complétude du module de visualisation de la page ESU et recherche de comment utiliser shinygouv::withSpinner_dsfr
parent 45e84d69
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ Imports:
ggridges,
glue,
golem (>= 0.4.1),
gouvdown,
highcharter,
htmltools,
leafem,
......@@ -26,8 +27,10 @@ Imports:
scales,
sf,
shiny (>= 1.7.4.1),
shinycustomloader,
shinybusy,
shinycssloaders,
shinygouv,
shinyWidgets,
stats,
tidyr,
utils
......
......@@ -45,6 +45,7 @@ importFrom(golem,add_resource_path)
importFrom(golem,bundle_resources)
importFrom(golem,favicon)
importFrom(golem,with_golem_options)
importFrom(gouvdown,gouv_colors)
importFrom(highcharter,hc_colors)
importFrom(highcharter,hc_exporting)
importFrom(highcharter,hc_plotOptions)
......@@ -82,6 +83,7 @@ importFrom(sf,st_drop_geometry)
importFrom(shiny,NS)
importFrom(shiny,downloadButton)
importFrom(shiny,downloadHandler)
importFrom(shiny,includeMarkdown)
importFrom(shiny,observeEvent)
importFrom(shiny,plotOutput)
importFrom(shiny,reactiveValues)
......@@ -95,7 +97,9 @@ importFrom(shiny,tagList)
importFrom(shiny,updateSelectInput)
importFrom(shiny,updateSelectizeInput)
importFrom(shiny,updateSliderInput)
importFrom(shinycustomloader,withLoader)
importFrom(shinyWidgets,useShinydashboard)
importFrom(shinybusy,add_busy_spinner)
importFrom(shinycssloaders,withSpinner)
importFrom(stats,setNames)
importFrom(tidyr,complete)
importFrom(tidyr,gather)
......
......@@ -5,12 +5,25 @@
#' @import shiny
#' @import shinygouv
#' @noRd
#' @importFrom gouvdown gouv_colors
#' @importFrom shiny includeMarkdown
#' @importFrom shinybusy add_busy_spinner
#' @importFrom shinyWidgets useShinydashboard
app_ui <- function(request) {
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
# shinybusy::add_busy_spinner(spin = "self-building-square",
# onstart = FALSE,
# position = "top-right",
# margins = c(30, 30),
# color = gouvdown::gouv_colors("f1")[[1]],
# height = "200px", width = "200px"),
#
# shinyWidgets::useShinydashboard(), # déforme le mise en page !
# Your application UI logic
navbarPage_dsfr(
id = "nav",
......
......@@ -8,7 +8,7 @@
#'
#' @importFrom shiny NS tagList
#' @import shinygouv
#' @importFrom shiny selectInput selectizeInput sliderInput downloadButton
#' @importFrom shiny selectInput sliderInput selectizeInput
mod_selection_explorer_mesures_ui <- function(id){
ns <- NS(id)
tagList(
......@@ -69,8 +69,9 @@ mod_selection_explorer_mesures_ui <- function(id){
#' selection_explorer_mesures Server Functions
#'
#' @noRd
#' @importFrom dplyr mutate pull filter select arrange
#' @importFrom shiny reactiveValues updateSelectInput updateSelectizeInput updateSliderInput observeEvent renderUI selectInput
#' @importFrom dplyr filter mutate pull select arrange
#' @importFrom sf st_drop_geometry
#' @importFrom shiny reactiveValues updateSelectInput updateSliderInput updateSelectizeInput observeEvent renderUI selectizeInput
mod_selection_explorer_mesures_server <- function(input, output, session, global){
# mod_selection_explorer_mesures_server <- function(id){
# moduleServer( id, function(input, output, session){
......
......@@ -11,7 +11,7 @@
#' @importFrom highcharter highchartOutput
#' @importFrom leaflet leafletOutput
#' @importFrom shiny downloadButton
#' @importFrom shinycustomloader withLoader
#' @importFrom shinycssloaders withSpinner
mod_visualisation_tableau_bord_ESU_ui <- function(id){
ns <- NS(id)
tagList(
......@@ -20,34 +20,34 @@ mod_visualisation_tableau_bord_ESU_ui <- function(id){
width = 6,
# "carte P90",
leaflet::leafletOutput(ns("tableau_bord_ESU_carte"))
),
),
column_dsfr(
width = 2,
# "donut",
highcharter::highchartOutput(ns("tableau_bord_ESU_graph_seqeau_prelevement"))
),
),
column_dsfr(
width = 4,
# "colonnes années",
# "colonnes ann\u00e9es",
highcharter::highchartOutput(ns("tableau_bord_ESU_graph_seqeau_col"))
)
),
)
),
tags$br(),
fluidRow_dsfr(
column_dsfr(
width = 6,
# "taux de quantification pour les 15 molécules les plus quantifiées",
# "taux de quantification pour les 15 mol\u00e9cules les plus quantifi\u00e9es",
highcharter::highchartOutput(ns("graph_taux_quantification_esu"))
),
),
column_dsfr(
width = 6,
# "recherche des 15 molécules les plus quantifiées",
# "recherche des 15 mol\u00e9cules les plus quantifi\u00e9es",
highcharter::highchartOutput(ns("graph_nombre_de_recherche_esu"))
)
),
)
),
tags$br(),
fluidRow_dsfr(
# "quantification par station : à voir",
# "quantification par station : \u00e0 voir",
column_dsfr(
width = 6,
#"Carte de quantification par station",
......@@ -55,38 +55,31 @@ mod_visualisation_tableau_bord_ESU_ui <- function(id){
actionButton_dsfr(
inputId = ns("molecule_valide"),
label = "Valider mon choix"
),
shinycustomloader::withLoader(
leaflet::leafletOutput(ns("carte_quantification")),
type="html",
loader="loader1"
)
),
leaflet::leafletOutput(ns("carte_quantification"))
),
column_dsfr(
width = 6,
"Tableau des stations pour la molécule sélectionnée",
# shinycustomloader::withLoader(
# DT::dataTableOutput(ns("tbl_quant")),
# type="html",
# loader="loader1"
# )
)
),
# "Tableau des stations pour la mol\u00e9cule s\u00e9lectionn\u00e9e",
DT::dataTableOutput(ns("tableau_quantification"))
),
tags$br(),
fluidRow_dsfr(
"Concentrations maximales et moyennes des molécules les plus quantifiées",
"Concentrations maximales et moyennes des mol\u00e9cules les plus quantifi\u00e9es",
tags$br(),
DT::dataTableOutput(ns("tb_tableau_concentration_esu")),
shiny::downloadButton(
outputId = ns("downloadtableau_esu"),
label = "T\u00e9l\u00e9charger le tableau",
class = "butt")
# tags$head(tags$style(".butt{background-color:white;} .butt{color: black;}"))
class = "butt"
)
),
tags$br()
)
)
}
#' visualisation_tableau_bord_ESU Server Functions
#'
#' @noRd
......@@ -102,6 +95,7 @@ mod_visualisation_tableau_bord_ESU_ui <- function(id){
#' @importFrom purrr set_names
#' @importFrom sf st_coordinates st_drop_geometry
#' @importFrom shiny reactiveValues observeEvent renderUI selectInput downloadHandler
#' @importFrom shinycssloaders withSpinner
#' @importFrom stats setNames
#' @importFrom tidyr complete
#' @importFrom utils write.csv2
......@@ -290,8 +284,17 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
}
locale$carte_seqeau <- carte_seqeau_fct(global$tableau_bord_ESU_SelectSage, locale$seqeau_filter, locale$tableau_bord_ESU_sage, locale$cadre_seqeau)
output$tableau_bord_ESU_carte <- leaflet::renderLeaflet(locale$carte_seqeau)
# output$tableau_bord_ESU_carte <- leaflet::renderLeaflet(locale$carte_seqeau)
# output$tableau_bord_ESU_carte <- leaflet::renderLeaflet(shinygouv::withSpinner_dsfr(locale$carte_seqeau, session))
# output$tableau_bord_ESU_carte <- leaflet::renderLeaflet(
# shinygouv::withSpinner_dsfr(
# expr = {
# locale$carte_seqeau
# }, session)
# )
# output$tableau_bord_ESU_carte <- shinygouv::withSpinner_dsfr(leaflet::renderLeaflet(locale$carte_seqeau), session)
# je n'ai pas compris comment s'utilise shinygouv::withSpinner_dsfr !
# Graphique répartition des stations par seqeau (donut) -----------
couleur_seqeau_filter_fct <- function(seqeau_filter){
......@@ -348,9 +351,9 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
buttons = list(contextButton = list(menuItems = c("downloadPNG", "downloadJPEG", "downloadPDF", "downloadCSV" )))
)
}
locale$donut_seqeau <- donut_seqeau_fct(locale$data_synthese_seqeau, global$tableau_bord_ESU_SelectAnnee, locale$couleur_seqeau_filter)
output$tableau_bord_ESU_graph_seqeau_prelevement <- highcharter::renderHighchart(locale$donut_seqeau)
locale$donut_seqeau <- donut_seqeau_fct(locale$data_synthese_seqeau,
global$tableau_bord_ESU_SelectAnnee,
locale$couleur_seqeau_filter)
# Graphique répartition des stations par seqeau pour toutes les années (colonnes) ------------
seqeau_filter_col_fct <- function(tableau_bord_ESU_station){
......@@ -400,9 +403,8 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
buttons = list(contextButton = list(menuItems = c("downloadPNG", "downloadJPEG", "downloadPDF", "downloadCSV" )))
)
}
locale$colonnes_seqeau <- colonnes_seqeau_fct(locale$data_synthese_seqeau_col, locale$couleur_seqeau_filter_col)
output$tableau_bord_ESU_graph_seqeau_col <- highcharter::renderHighchart(locale$colonnes_seqeau)
locale$colonnes_seqeau <- colonnes_seqeau_fct(locale$data_synthese_seqeau_col,
locale$couleur_seqeau_filter_col)
# Graphique taux de quantification ------------
ESU_graph_taux_quantification_fct <- function(tableau_bord_ESU_SelectAnnee, tableau_bord_ESU_SelectSage){
......@@ -440,9 +442,8 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
buttons = list(contextButton = list(menuItems = c("downloadPNG", "downloadJPEG", "downloadPDF")))
)
}
locale$ESU_graph_taux_quantification <- ESU_graph_taux_quantification_fct(global$tableau_bord_ESU_SelectAnnee, global$tableau_bord_ESU_SelectSage)
output$graph_taux_quantification_esu <- highcharter::renderHighchart(locale$ESU_graph_taux_quantification)
locale$ESU_graph_taux_quantification <- ESU_graph_taux_quantification_fct(global$tableau_bord_ESU_SelectAnnee,
global$tableau_bord_ESU_SelectSage)
# Graphique sur le nombre de recherche -----------
ESU_graph_nombre_de_recherche_fct <- function(tableau_bord_ESU_SelectAnnee, tableau_bord_ESU_SelectSage){
......@@ -474,13 +475,10 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
buttons = list(contextButton = list(menuItems = c("downloadPNG", "downloadJPEG", "downloadPDF", "downloadCSV" )))
)
}
locale$ESU_graph_nombre_de_recherche <- ESU_graph_nombre_de_recherche_fct(global$tableau_bord_ESU_SelectAnnee, global$tableau_bord_ESU_SelectSage)
output$graph_nombre_de_recherche_esu <- highcharter::renderHighchart(locale$ESU_graph_nombre_de_recherche)
# carte de quantification par station -----------
locale$ESU_graph_nombre_de_recherche <- ESU_graph_nombre_de_recherche_fct(global$tableau_bord_ESU_SelectAnnee,
global$tableau_bord_ESU_SelectSage)
# carte et tableau de quantification par station -----------
ESU_parametre_quantification_station_fct <- function(tableau_bord_ESU_SelectAnnee, tableau_bord_ESU_SelectSage){
ESU_parametre_quantification_station <- quantification_esu %>%
dplyr::filter(
......@@ -490,8 +488,8 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
dplyr::pull(nom_parametre) %>%
unique()
}
locale$ESU_parametre_quantification_station <- ESU_parametre_quantification_station_fct(global$tableau_bord_ESU_SelectAnnee, global$tableau_bord_ESU_SelectSage)
locale$ESU_parametre_quantification_station <- ESU_parametre_quantification_station_fct(global$tableau_bord_ESU_SelectAnnee,
global$tableau_bord_ESU_SelectSage)
quantification_station_esu_fct <- function(tableau_bord_ESU_SelectSage, tableau_bord_ESU_SelectAnnee, ESU_parametre_quantification_station){
quant <- matrice_esu %>%
dplyr::filter(nom_parametre != "cumul") %>%
......@@ -535,27 +533,22 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
)
}
}
locale$quantification_station_esu <- quantification_station_esu_fct(global$tableau_bord_ESU_SelectSage, global$tableau_bord_ESU_SelectAnnee, locale$ESU_parametre_quantification_station)
output$liste_15_molecules <- shiny::renderUI({
shiny::selectInput(
inputId = ns("select_molecule"),
label = "Sélectionner une molécule parmi les 15 plus quantifiées",
choices = locale$ESU_parametre_quantification_station
)
})
shiny::observeEvent(input$molecule_valide,{ # c(input$tableau_bord_ESU_valide,input$molecule_valide) fait planter l'application
locale$quantification_station_esu <- quantification_station_esu_fct(global$tableau_bord_ESU_SelectSage,
global$tableau_bord_ESU_SelectAnnee,
locale$ESU_parametre_quantification_station)
shiny::observeEvent(input$molecule_valide,{
ESU_quantification_station_parametre_fct <- function(quantification_station_esu, select_molecule){
ESU_quantification_station_parametre <- station_esu %>%
dplyr::select(code_station) %>%
dplyr::left_join(quantification_station_esu) %>%
dplyr::filter(nom_parametre == select_molecule)
}
locale$ESU_quantification_station_parametre <- ESU_quantification_station_parametre_fct(locale$quantification_station_esu, input$select_molecule)
ESU_carte_quantification_fct <- function(tableau_bord_ESU_SelectSage, ESU_quantification_station_parametre, tableau_bord_ESU_sage, cadre_seqeau){
locale$ESU_quantification_station_parametre <- ESU_quantification_station_parametre_fct(locale$quantification_station_esu,
input$select_molecule)
ESU_carte_quantification_fct <- function(tableau_bord_ESU_SelectSage,
ESU_quantification_station_parametre,
tableau_bord_ESU_sage,
cadre_seqeau){
pal <- leaflet::colorNumeric(
palette = "Blues",
......@@ -577,6 +570,7 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
leaflet::addProviderTiles(provider = "CartoDB.Positron") %>%
leaflet::addPolygons(
data = n_region_exp_r52,
group = "zoomer sur la r\u00e9gion",
color = "#444444",
weight = 1,
smoothFactor = 0.5,
......@@ -616,7 +610,9 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
labFormat = leaflet::labelFormat(suffix = " %",digits = 0),
title = "Taux de quantification",
opacity = 1
)
) %>%
leaflet.extras::addFullscreenControl(position = "topright") %>%
leafem::addHomeButton(group = "zoomer sur la r\u00e9gion", position = "bottomright", add = TRUE)
} else {
leaflet::leaflet(
ESU_quantification_station_parametre,
......@@ -625,6 +621,7 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
leaflet::addProviderTiles(provider = "CartoDB.Positron") %>%
leaflet::addPolygons(
data = n_region_exp_r52,
group = "zoomer sur la r\u00e9gion",
color = "#444444",
weight = 1,
smoothFactor = 0.5,
......@@ -675,29 +672,26 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
labFormat = leaflet::labelFormat(suffix = " %", digits = 0),
title = "Taux de quantification",
opacity = 1
)
) %>%
leaflet.extras::addFullscreenControl(position = "topright") %>%
leafem::addHomeButton(group = "zoomer sur la r\u00e9gion", position = "bottomright", add = TRUE)
}
}
locale$ESU_carte_quantification <- ESU_carte_quantification_fct(global$tableau_bord_ESU_SelectSage, locale$ESU_quantification_station_parametre, locale$tableau_bord_ESU_sage, locale$cadre_seqeau)
output$carte_quantification <- renderLeaflet(locale$ESU_carte_quantification)
}, ignoreNULL = TRUE, ignoreInit = TRUE) # à voir valeur de ignoreInit
# tableau des stations par molécule (quantification,recherche) -----------
locale$ESU_carte_quantification <- ESU_carte_quantification_fct(global$tableau_bord_ESU_SelectSage,
locale$ESU_quantification_station_parametre,
locale$tableau_bord_ESU_sage,
locale$cadre_seqeau)
ESU_tableau_quantification_fct <- function(ESU_quantification_station_parametre){
ESU_tableau_quantification <- ESU_quantification_station_parametre %>%
dplyr::select(c(libelle_station,taux_quant,freq_depas,rech,trouve,pas_trouve)) %>%
sf::st_drop_geometry() %>%
stats::setNames(
c("Station","Taux de quantification","Fr\u00e9quence de d\u00e9passement",
"Recherch\u00e9e","Trouv\u00e9e","Non trouv\u00e9e")
)
}
locale$ESU_tableau_quantification <- ESU_tableau_quantification_fct(locale$ESU_quantification_station_parametre)
}, ignoreNULL = TRUE, ignoreInit = FALSE) # à voir valeur de ignoreInit
# Tableau synthèse des concentrations retrouvée par molécule -------------
ESU_tableau_concentration_fct <- function(tableau_bord_ESU_SelectAnnee, tableau_bord_ESU_SelectSage){
......@@ -715,24 +709,40 @@ mod_visualisation_tableau_bord_ESU_server <- function(id, global){
}
locale$ESU_tableau_concentration <- ESU_tableau_concentration_fct(global$tableau_bord_ESU_SelectAnnee, global$tableau_bord_ESU_SelectSage)
output$tb_tableau_concentration_esu <- DT::renderDataTable(
locale$ESU_tableau_concentration,
filter = "bottom",
options = list(
language = list(url = "//cdn.datatables.net/plug-ins/1.10.11/i18n/French.json"),
autoWidth = T
)
)
}) # fin de observeEvent principal
output$downloadtableau_esu <- shiny::downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep = "")
},
content = function(file) {
utils::write.csv2(locale$ESU_tableau_concentration, file, row.names = FALSE)
}
output$tableau_bord_ESU_carte <- leaflet::renderLeaflet(locale$carte_seqeau)
output$tableau_bord_ESU_graph_seqeau_prelevement <- highcharter::renderHighchart(locale$donut_seqeau)
output$tableau_bord_ESU_graph_seqeau_col <- highcharter::renderHighchart(locale$colonnes_seqeau)
output$graph_taux_quantification_esu <- highcharter::renderHighchart(locale$ESU_graph_taux_quantification)
output$graph_nombre_de_recherche_esu <- highcharter::renderHighchart(locale$ESU_graph_nombre_de_recherche)
output$liste_15_molecules <- shiny::renderUI({
shiny::selectInput(
inputId = ns("select_molecule"),
label = "S\u00e9lectionner une mol\u00e9cule parmi les 15 plus quantifi\u00e9es",
choices = locale$ESU_parametre_quantification_station
)
})
output$carte_quantification <- renderLeaflet(locale$ESU_carte_quantification)
output$tableau_quantification <- DT::renderDataTable(locale$ESU_tableau_quantification)
output$tb_tableau_concentration_esu <- DT::renderDataTable(
locale$ESU_tableau_concentration,
filter = "bottom",
options = list(
language = list(url = "//cdn.datatables.net/plug-ins/1.10.11/i18n/French.json"),
autoWidth = T
)
)
output$downloadtableau_esu <- shiny::downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep = "")
},
content = function(file) {
utils::write.csv2(locale$ESU_tableau_concentration, file, row.names = FALSE)
}
)
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment