Commit fe4117bc authored by cedricbriandgithub's avatar cedricbriandgithub
Browse files

Merge branch 'develop_angarg' of git@forgemia.inra.fr:stacomi/stacoshiny.git into develop_angarg

parents 821be67e b32e63b5
Pipeline #61847 failed with stage
in 32 seconds
#' annuel UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
#' @importFrom shinydashboard tabItem box
mod_annuel_ui <- function(id){
ns <- NS(id)
tabItem(tabName = "annuel",
shinydashboardPlus::box(
title = "S\u00e9lections :",
solidHeader = TRUE,
#icon("list-alt"),
collapsible = TRUE,
status="primary",
width = 3,
sliderInput(ns("slider_annuel_date"),
label = h5("Choisissez l'ann\u00e9e de d\u00e9but et de fin :"),
min = 1980,
max = CY,
value = c(2011, CY)),
mod_ref_taxa_ui("ref_taxa_mod_annuel"),
mod_ref_stage_ui("ref_stage_mod_annuel"),
checkboxGroupInput(ns("choix_sorties"),
label = h5("Choisissez les sorties graphiques ou tableaux :"),
choices = list(
"plot_barplot" = 1,
"plot_point" = 2,
"tab_annuel_data" = 3),
selected = 1),
actionBttn(
inputId = ns("bttn_annuel"),
label = "OK",
style = "fill",
color = "primary"
)
),
shinydashboardPlus::box(
id=ns("box_annuel_barplot"),
title="Barplot",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
collapsed=TRUE,
plotOutput(ns("plot_annuel_barplot"))
),
shinydashboardPlus::box(
id=ns("box_annuel_point"),
title="Point",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
collapsed=TRUE,
plotOutput(ns("plot_annuel_point"))
),
shinydashboardPlus::box(
id=ns("box_annuel_data"),
title="Données",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
collapsed=TRUE,
htmlOutput(ns("tab_annuel_data"))
)
)
}
#' annuel Server Functions
#' @importFrom shinipsum random_ggplot random_DT
#' @importFrom DT renderDT
#' @param id identifier of the module
#' @param DD reactive data to pass data between modules
#' @noRd
mod_annuel_server <- function(id, DD){
moduleServer( id, function(input, output, session){
ns <- session$ns
observeEvent(input$bttn_annuel, {
shinyCatch({
validate(need(exists("envir_stacomi"), "Le programme stacomi doit être lancé"))
db_connection <- envir_stacomi$db_connection
validate(need(!is.null(db_connection), "db needs connection"))
r_annual <- new("report_annual")
ref_dc <- base::get("ref_dc", envir=envir_stacomi)
ref_taxa <- base::get("ref_taxa", envir=envir_stacomi)
ref_stage <- base::get("ref_stage", envir=envir_stacomi)
validate(need(length(ref_dc@dc_selected)>0, "Pas de DC sélectionné"))
validate(need(length(ref_taxa@taxa_selected)>0, "pas de taxon sélectionné"))
validate(need(length(ref_stage@stage_selected)>0, "pas de stade sélectionné"))
r_annual <- choice_c(r_annual,
dc=ref_dc@dc_selected,
taxa=ref_taxa@taxa_selected,
stage=ref_stage@stage_selected,
start_year=input$slider_annuel_date[1],
end_year=input$slider_annuel_date[2],
silent=TRUE)
# launching charge will also load classes associated with the report
# e.g. report_ope, report_df, report_dc
r_annual <- connect(r_annual)
if (nrow(r_annual@data)==0){
warning("no data available")
} else {
if ("1" %in% input$choix_sorties) {
if (input$box_annuel_barplot$collapsed) shinydashboardPlus::updateBox("box_annuel_barplot", action = "toggle")
output$plot_annuel_barplot <- renderPlot({
stacomiR::barplot(r_annual)
})
} else {
if (!input$box_annuel_barplot$collapsed) shinydashboardPlus::updateBox("box_annuel_barplot", action = "toggle")
}#end ifelse "1"
if ("2" %in% input$choix_sorties) {
if (input$box_annuel_point$collapsed) shinydashboardPlus::updateBox("box_annuel_point", action = "toggle")
output$plot_annuel_point <- renderPlot({
stacomiR::plot(r_annual)
})
} else {
if (!input$box_annuel_point$collapsed) shinydashboardPlus::updateBox("box_annuel_point", action = "toggle")
}# end ifelse "2"
if ("3" %in% input$choix_sorties) {
if (input$box_annuel_data$collapsed) shinydashboardPlus::updateBox("box_annuel_data", action = "toggle")
output$tab_annuel_data <- renderUI({
xt <- stacomiR::xtable(r_annual)
HTML(xtable::print.xtable(xt, type = "html"))
})
} else {
if (!input$box_annuel_data$collapsed) shinydashboardPlus::updateBox("box_annuel_data", action = "toggle")
} # end ifelse "3"
} # end else
}) # end shiny catch
})
})
}
## To be copied in the UI
# mod_annuel_ui("annuel_ui_1")
## To be copied in the server
# mod_annuel_server("annuel_ui_1")
#' annuel UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
#' @importFrom shinydashboard tabItem box
mod_annuel_ui <- function(id){
ns <- NS(id)
tabItem(tabName = "annuel",
shinydashboardPlus::box(
title = "S\u00e9lections :",
solidHeader = TRUE,
#icon("list-alt"),
collapsible = TRUE,
status="primary",
width = 3,
sliderInput(ns("slider_annuel_date"),
label = h5("Choisissez l'ann\u00e9e de d\u00e9but et de fin :"),
min = 1980,
max = CY,
value = c(2011, CY),
sep = ""),
mod_ref_taxa_ui("ref_taxa_mod_annuel"),
mod_ref_stage_ui("ref_stage_mod_annuel"),
checkboxGroupInput(ns("choix_sorties"),
label = h5("Choisissez les sorties graphiques ou tableaux :"),
choices = list(
"plot_barplot" = 1,
"plot_point" = 2,
"tab_annuel_data" = 3),
selected = 1),
actionBttn(
inputId = ns("bttn_annuel"),
label = "OK",
style = "fill",
color = "primary"
)
),
shinydashboardPlus::box(
id=ns("box_annuel_barplot"),
title="Barplot",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
collapsed=TRUE,
plotOutput(ns("plot_annuel_barplot"))
),
shinydashboardPlus::box(
id=ns("box_annuel_point"),
title="Point",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
collapsed=TRUE,
plotOutput(ns("plot_annuel_point"))
),
shinydashboardPlus::box(
id=ns("box_annuel_data"),
title="Données",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
collapsed=TRUE,
htmlOutput(ns("tab_annuel_data"))
)
)
}
#' annuel Server Functions
#' @importFrom shinipsum random_ggplot random_DT
#' @importFrom DT renderDT
#' @param id identifier of the module
#' @param DD reactive data to pass data between modules
#' @noRd
mod_annuel_server <- function(id, DD){
moduleServer( id, function(input, output, session){
ns <- session$ns
observeEvent(input$bttn_annuel, {
shinyCatch({
validate(need(exists("envir_stacomi"), "Le programme stacomi doit être lancé"))
db_connection <- envir_stacomi$db_connection
validate(need(!is.null(db_connection), "db needs connection"))
r_annual <- new("report_annual")
ref_dc <- base::get("ref_dc", envir=envir_stacomi)
ref_taxa <- base::get("ref_taxa", envir=envir_stacomi)
ref_stage <- base::get("ref_stage", envir=envir_stacomi)
validate(need(length(ref_dc@dc_selected)>0, "Pas de DC sélectionné"))
validate(need(length(ref_taxa@taxa_selected)>0, "pas de taxon sélectionné"))
validate(need(length(ref_stage@stage_selected)>0, "pas de stade sélectionné"))
r_annual <- choice_c(r_annual,
dc=ref_dc@dc_selected,
taxa=ref_taxa@taxa_selected,
stage=ref_stage@stage_selected,
start_year=input$slider_annuel_date[1],
end_year=input$slider_annuel_date[2],
silent=TRUE)
# launching charge will also load classes associated with the report
# e.g. report_ope, report_df, report_dc
r_annual <- connect(r_annual)
if (nrow(r_annual@data)==0){
warning("no data available")
} else {
if ("1" %in% input$choix_sorties) {
if (input$box_annuel_barplot$collapsed) shinydashboardPlus::updateBox("box_annuel_barplot", action = "toggle")
output$plot_annuel_barplot <- renderPlot({
stacomiR::barplot(r_annual)
})
} else {
if (!input$box_annuel_barplot$collapsed) shinydashboardPlus::updateBox("box_annuel_barplot", action = "toggle")
}#end ifelse "1"
if ("2" %in% input$choix_sorties) {
if (input$box_annuel_point$collapsed) shinydashboardPlus::updateBox("box_annuel_point", action = "toggle")
output$plot_annuel_point <- renderPlot({
stacomiR::plot(r_annual)
})
} else {
if (!input$box_annuel_point$collapsed) shinydashboardPlus::updateBox("box_annuel_point", action = "toggle")
}# end ifelse "2"
if ("3" %in% input$choix_sorties) {
if (input$box_annuel_data$collapsed) shinydashboardPlus::updateBox("box_annuel_data", action = "toggle")
output$tab_annuel_data <- renderUI({
xt <- stacomiR::xtable(r_annual)
HTML(xtable::print.xtable(xt, type = "html"))
})
} else {
if (!input$box_annuel_data$collapsed) shinydashboardPlus::updateBox("box_annuel_data", action = "toggle")
} # end ifelse "3"
} # end else
}) # end shiny catch
})
})
}
## To be copied in the UI
# mod_annuel_ui("annuel_ui_1")
## To be copied in the server
# mod_annuel_server("annuel_ui_1")
......@@ -26,8 +26,8 @@ mod_civ_poids_ui <- function(id){
checkboxGroupInput(ns("choix_sorties"),
label = h5("Choisissez les sorties graphiques ou tableaux :"),
choices = list(
"plot_civpoids_1" = 1,
"plot_civpoids_2" = 2,
"Poids en fonction de la date" = 1,
"Tendance saisionnière du poids" = 2,
"plot_civpoids_3" = 3,
"tab_civpoids" = 4,
"tab_civpoids2" = 5),
......@@ -184,8 +184,8 @@ mod_civ_poids_server <- function(id, DD) {
print(tab2)
})
} else {
if (!input$box_tab_civpoid$collapsed)
shinydashboardPlus::updateBox("box_tab_civpoid", action = "toggle")
if (!input$box_tab_civpoids$collapsed)
shinydashboardPlus::updateBox("box_tab_civpoids", action = "toggle")
}
if ("5" %in% input$choix_sorties) {
if (input$box_tab_civpoids2$collapsed)
......@@ -196,7 +196,7 @@ mod_civ_poids_server <- function(id, DD) {
print(tab4)
})
} else {
if (!input$box_tab_civpoid2$collapsed)
if (!input$box_tab_civpoids2$collapsed)
shinydashboardPlus::updateBox("box_tab_civpoids2", action = "toggle")
}
})
......
#' espece UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
#' @importFrom shinydashboard tabItem box
mod_espece_ui <- function(id){
ns <- NS(id)
tabItem(tabName = "espece",
shinydashboardPlus::box(title = "S\u00e9lections :",
solidHeader = TRUE,
status="primary",
collapsible = TRUE,
width = 3,
sliderInput(ns("annee"),
label = h5("Choisissez l\'ann\u00e9e"),
min = 1980,
max = CY,
value = c(2011, CY)),
#La checkbox n'a pas assez d'option - utiliser un slider pour limiter les trop gros effectifs
# checkboxGroupInput("choix_taxon", label = h5("Choisissez les sorties graphiques ou tableaux :"),
# choices = list("A" = 1, "B" = 2, "C" = 3,"D"=4,"E"=5,"F"=6,"G"=7,"H"=8),
# selected = c(A,B,C,D,E,F,G,H)),
mod_ref_taxa_ui("ref_taxa_espece"),
selectizeInput(ns("pas_temps"), h5('Choisissez un d\u00e9coupage temporel :'),
selected="Aucun", choices = c("Aucun","Semaine","Mois","Ann\u00e9e"),
multiple = FALSE),
checkboxGroupInput(ns("choix_sorties"), label = h4("Choisissez les sorties graphiques ou tableaux :"),
choices = list("plot_pie" = 1, "plot_barplot" = 2, "tab_summary"= 3),
selected = 1),
actionBttn(
inputId = ns("bttn_esp"),
label = "OK",
style = "fill",
color = "primary"
)
),
shinydashboardPlus::box(
id=ns("box_esp_pie"),
title="pie",
collapsible = TRUE,
solidHeader = TRUE,
collapsed=TRUE,
width=9,
status="primary",
plotOutput(ns("plot_esp_pie"))
),
shinydashboardPlus::box(
id=ns("box_esp_barplot"),
title="barplot",
collapsible = TRUE,
solidHeader = TRUE,
collapsed=TRUE,
width=9,
status="primary",
plotOutput(ns("plot_esp_barplot"))
),
shinydashboardPlus::box(
id=ns("box_esp_summary"),
title="summary",
collapsible = TRUE,
solidHeader = TRUE,
collapsed=TRUE,
width=9,
status="primary",
DTOutput(ns("tab_esp_summary"))
)
)
}
#' espece Server Functions
#' @importFrom DT renderDT
#' @noRd
mod_espece_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
observeEvent(input$bttn_esp, {
shinyCatch({
validate(need(exists("envir_stacomi"), "Le programme stacomi doit être lancé"))
db_connection <- envir_stacomi$db_connection
validate(need(!is.null(db_connection), "db needs connection"))
bilesp <- new("report_species")
ref_dc <- base::get("ref_dc", envir=envir_stacomi)
validate(need(length(ref_dc@dc_selected)>0, "Pas de DC sélectionné"))
pas_temps <- input$pas_temps
pas_temps_english <- switch(pas_temps,"Aucun"="none",
"Semaine"="week",
"Mois"="month",
"Ann\u00e9e"= "year"
)
bilesp <- choice_c(
bilesp,
dc = ref_dc@dc_selected,
split = pas_temps_english,
start_year = input$annee[1],
end_year = input$annee[2],
silent = FALSE
)
bilesp <- charge(bilesp, silent = TRUE)
bilesp <- connect(bilesp, silent = TRUE)
bilesp <- calcule(bilesp, silent = TRUE)
if (nrow(bilesp@data)==0){
warning("no data available")
} else {
if ("1" %in% input$choix_sorties) {
if (input$box_esp_pie$collapsed) shinydashboardPlus::updateBox("box_esp_pie", action = "toggle")
output$plot_esp_pie <- renderPlot({
stacomiR::plot(bilesp, plot.type = "pie", silent = TRUE)
})
} else {
if (!input$box_esp_pie$collapsed) shinydashboardPlus::updateBox("box_esp_pie", action = "toggle")
}#end ifelse "1"
if ("2" %in% input$choix_sorties) {
if (input$box_esp_barplot$collapsed) shinydashboardPlus::updateBox("box_esp_barplot", action = "toggle")
output$plot_esp_barplot <- renderPlot({
stacomiR::plot(bilesp, plot.type = "barplot", silent = TRUE)
})
} else {
if (!input$box_esp_barplot$collapsed) shinydashboardPlus::updateBox("box_esp_barplot", action = "toggle")
}# end ifelse "2"
if ("3" %in% input$choix_sorties) {
if (input$box_esp_summary$collapsed) shinydashboardPlus::updateBox("box_esp_summary", action = "toggle")
output$tab_esp_summary <- renderDT({
bilesp@calcdata
})
} else {
if (!input$box_esp_summary$collapsed) shinydashboardPlus::updateBox("box_esp_summary", action = "toggle")
} # end ifelse "3"
} # end else
}) # end shiny catch
},
ignoreInit = TRUE) # end observe
})
}
## To be copied in the UI
# mod_espece_ui("espece_ui_1")
## To be copied in the server
# mod_espece_server("espece_ui_1")
#' espece UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
#' @importFrom shinydashboard tabItem box
mod_espece_ui <- function(id){
ns <- NS(id)
tabItem(tabName = "espece",
shinydashboardPlus::box(title = "S\u00e9lections :",
solidHeader = TRUE,
status="primary",
collapsible = TRUE,
width = 3,
sliderInput(ns("annee"),
label = h5("Choisissez l\'ann\u00e9e"),
min = 1980,
max = CY,
value = c(2011, CY),
sep= ""),
#La checkbox n'a pas assez d'option - utiliser un slider pour limiter les trop gros effectifs
# checkboxGroupInput("choix_taxon", label = h5("Choisissez les sorties graphiques ou tableaux :"),
# choices = list("A" = 1, "B" = 2, "C" = 3,"D"=4,"E"=5,"F"=6,"G"=7,"H"=8),
# selected = c(A,B,C,D,E,F,G,H)),
mod_ref_taxa_ui("ref_taxa_espece"),
selectizeInput(ns("pas_temps"), h5('Choisissez un d\u00e9coupage temporel :'),
selected="Aucun", choices = c("Aucun","Semaine","Mois","Ann\u00e9e"),
multiple = FALSE),
checkboxGroupInput(ns("choix_sorties"), label = h4("Choisissez les sorties graphiques ou tableaux :"),
choices = list("plot_pie" = 1, "plot_barplot" = 2, "tab_summary"= 3),
selected = 1),
actionBttn(
inputId = ns("bttn_esp"),
label = "OK",
style = "fill",
color = "primary"
)
),
shinydashboardPlus::box(
id=ns("box_esp_pie"),
title="pie",
collapsible = TRUE,
solidHeader = TRUE,
collapsed=TRUE,
width=9,
status="primary",
plotOutput(ns("plot_esp_pie"))
),
shinydashboardPlus::box(
id=ns("box_esp_barplot"),
title="barplot",
collapsible = TRUE,
solidHeader = TRUE,
collapsed=TRUE,
width=9,
status="primary",
plotOutput(ns("plot_esp_barplot"))
),
shinydashboardPlus::box(
id=ns("box_esp_summary"),
title="summary",
collapsible = TRUE,
solidHeader = TRUE,
collapsed=TRUE,
width=9,
status="primary",
DTOutput(ns("tab_esp_summary"))
)
)
}
#' espece Server Functions
#' @importFrom DT renderDT
#' @noRd
mod_espece_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
observeEvent(input$bttn_esp, {
shinyCatch({
validate(need(exists("envir_stacomi"), "Le programme stacomi doit être lancé"))
db_connection <- envir_stacomi$db_connection
validate(need(!is.null(db_connection), "db needs connection"))
bilesp <- new("report_species")
ref_dc <- base::get("ref_dc", envir=envir_stacomi)
validate(need(length(ref_dc@dc_selected)>0, "Pas de DC sélectionné"))
pas_temps <- input$pas_temps
pas_temps_english <- switch(pas_temps,"Aucun"="none",
"Semaine"="week",
"Mois"="month",
"Ann\u00e9e"= "year"
)
bilesp <- choice_c(
bilesp,
dc = ref_dc@dc_selected,
split = pas_temps_english,
start_year = input$annee[1],
end_year = input$annee[2],
silent = FALSE
)
bilesp <- charge(bilesp, silent = TRUE)
bilesp <- connect(bilesp, silent = TRUE)
bilesp <- calcule(bilesp, silent = TRUE)
if (nrow(bilesp@data)==0){
warning("no data available")
} else {
if ("1" %in% input$choix_sorties) {
if (input$box_esp_pie$collapsed) shinydashboardPlus::updateBox("box_esp_pie", action = "toggle")
output$plot_esp_pie <- renderPlot({
stacomiR::plot(bilesp, plot.type = "pie", silent = TRUE)
})
} else {
if (!input$box_esp_pie$collapsed) shinydashboardPlus::updateBox("box_esp_pie", action = "toggle")
}#end ifelse "1"
if ("2" %in% input$choix_sorties) {
if (input$box_esp_barplot$collapsed) shinydashboardPlus::updateBox("box_esp_barplot", action = "toggle")
output$plot_esp_barplot <- renderPlot({
stacomiR::plot(bilesp, plot.type = "barplot", silent = TRUE)
})
} else {
if (!input$box_esp_barplot$collapsed) shinydashboard