From 20739335c358fd2b0b79a3ef5a97cbc74b7287c4 Mon Sep 17 00:00:00 2001
From: thierrychambert <thierry.chambert@gmail.com>
Date: Mon, 16 Aug 2021 16:48:35 +0200
Subject: [PATCH] Cleaned layout for parameter input, using show/hide
 wellPanels.

---
 inst/ShinyApp/server.R |  65 ++++++++--
 inst/ShinyApp/ui.R     | 286 +++++++++++++++++++++++------------------
 2 files changed, 212 insertions(+), 139 deletions(-)

diff --git a/inst/ShinyApp/server.R b/inst/ShinyApp/server.R
index d7bca87..becdaaf 100644
--- a/inst/ShinyApp/server.R
+++ b/inst/ShinyApp/server.R
@@ -2,8 +2,20 @@ server <- function(input, output, session){
 
 
   ##--------------------------------------------
-  ##  Hide all inputs excepted actionButtons  --
+  ##  Hide/Show : level 1
   ##--------------------------------------------
+
+  ## Fatalities
+  output$hide_fatalities <- eventReactive({
+    input$button_fatalities
+  },{
+    if(input$button_fatalities%%2 == 1) TRUE else FALSE
+  }, ignoreInit = TRUE)
+
+  outputOptions(output, "hide_fatalities", suspendWhenHidden = FALSE)
+
+
+  ## Population Size
   output$hide_pop_size <- eventReactive({
     input$button_pop_size
   },{
@@ -13,13 +25,42 @@ server <- function(input, output, session){
   outputOptions(output, "hide_pop_size", suspendWhenHidden = FALSE)
 
 
+  ## Population Growth
+  output$hide_pop_growth <- eventReactive({
+    input$button_pop_growth
+  },{
+    if(input$button_pop_growth%%2 == 1) TRUE else FALSE
+  }, ignoreInit = TRUE)
+
+  outputOptions(output, "hide_pop_growth", suspendWhenHidden = FALSE)
+
+
+  ## Carrying capacity
+  output$hide_carrying_cap <- eventReactive({
+    input$button_carrying_cap
+  },{
+    if(input$button_carrying_cap%%2 == 1) TRUE else FALSE
+  }, ignoreInit = TRUE)
+
+  outputOptions(output, "hide_carrying_cap", suspendWhenHidden = FALSE)
+
+  # Display Carrying capacity Unit Info
+  output$carrying_cap_unit_info <- renderText({
+    if(input$pop_size_unit == "Npair"){
+      paste0("Nombre de couple")
+    } else {
+      paste0("Effectif total")
+    }
+  })
+
+
   ##--------------------------------------------
-  ##  Hide all inputs excepted actionButtons  --
+  ##  Hide/Show : level 2
   ##--------------------------------------------
   observe({
 
     #shinyjs::hide("fatal_constant")
-    shinyjs::hide("fatalities_input_type")
+    #shinyjs::hide("fatalities_input_type")
     shinyjs::hide("fatalities_mean")
     shinyjs::hide("fatalities_se")
     shinyjs::hide("fatalities_mat_expert")
@@ -28,18 +69,13 @@ server <- function(input, output, session){
     shinyjs::hide("fatalities_mat_cumulated")
 
     #shinyjs::hide("pop_size_unit")
-    shinyjs::hide("pop_size_input_type")
+    #shinyjs::hide("pop_size_input_type")
     shinyjs::hide("pop_size_mean")
     shinyjs::hide("pop_size_se")
     shinyjs::hide("pop_size_mat_expert")
     shinyjs::hide("pop_size_run_expert")
 
-    shinyjs::hide("carrying_cap_input_type")
-    shinyjs::hide("carrying_capacity")
-    shinyjs::hide("carrying_cap_mat_expert")
-    shinyjs::hide("carrying_cap_run_expert")
-
-    shinyjs::hide("pop_growth_input_type")
+    #shinyjs::hide("pop_growth_input_type")
     shinyjs::hide("pop_growth_mean")
     shinyjs::hide("pop_growth_se")
     shinyjs::hide("pop_growth_mat_expert")
@@ -47,6 +83,12 @@ server <- function(input, output, session){
     shinyjs::hide("pop_trend")
     shinyjs::hide("pop_trend_strength")
 
+
+    #shinyjs::hide("carrying_cap_input_type")
+    shinyjs::hide("carrying_capacity")
+    shinyjs::hide("carrying_cap_mat_expert")
+    shinyjs::hide("carrying_cap_run_expert")
+
     shinyjs::hide("mat_fill_vr")
 
 
@@ -109,7 +151,7 @@ server <- function(input, output, session){
 
     # Show inputs for population trend part
 
-    if(input$button_pop_trend%%2 == 1){
+    if(input$button_pop_growth%%2 == 1){
       shinyjs::show("pop_growth_input_type")
       if(input$pop_growth_input_type == "val"){
         shinyjs::show("pop_growth_mean")
@@ -614,7 +656,6 @@ server <- function(input, output, session){
 
 
   ## Poplutation size
-
   output$pop_size_unit_info <- renderText({
     if(input$pop_size_unit == "Npair"){
       paste0("Nombre de couple")
diff --git a/inst/ShinyApp/ui.R b/inst/ShinyApp/ui.R
index d0a5a24..b74dd8d 100644
--- a/inst/ShinyApp/ui.R
+++ b/inst/ShinyApp/ui.R
@@ -142,55 +142,61 @@ rm(list = ls(all.names = TRUE))
       {column(width = 3,
 
               tags$style(HTML('#button_fatalities{background-color:#C2C8D3}')),
-              actionButton(inputId = "button_fatalities",
+              actionButton(inputId = "button_fatalities", width = '100%',
                            label = tags$span("Mortalités annuelles", style = "font-weight: bold; font-size: 18px;")
               ),
 
-              br(""),
-
               ### Part for non-cumulated impacts
               # Input type
-              radioButtons(inputId = "fatalities_input_type",
-                           label = "Type de saisie",
-                           choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")),
-
-              # Values
-              numericInput(inputId = "fatalities_mean",
-                           label = "Moyenne des mortalités annuelles",
-                           value = 5,
-                           min = 0, max = Inf, step = 0.5),
-              numericInput(inputId = "fatalities_se",
-                           label = "Erreur-type des mortalités annuelles",
-                           value = 0.05,
-                           min = 0, max = Inf, step = 0.1),
-
-              # Matrix for expert elicitation
-              matrixInput(inputId = "fatalities_mat_expert",
-                          value = matrix(data = eli_fatalities, nrow = 4, ncol = 5,
-                                         dimnames = list(c("#1", "#2", "#3", "#4"),
-                                                         c("Poids", "Min", "Best", "Max", "% IC" )),
-                                         byrow = TRUE),
-                          class = "numeric",
-                          rows = list(names = TRUE),
-                          cols = list(names = TRUE)),
-
-              actionButton(inputId = "fatalities_run_expert", label = "Utiliser valeurs experts"),
-
-              ### Part for cumulated impacts
-
-              numericInput(inputId = "farm_number_cumulated",
-                           label = "Nombre de parcs éoliens",
-                           value = 3, min = 2, max = Inf, step = 1),
-
-              matrixInput(inputId = "fatalities_mat_cumulated",
-                          value = matrix(init_cumul, 3, 3,
-                                         dimnames = list(c(paste0("Parc n°", c(1:3))),
-                                                         c("Moyenne",
-                                                           "Erreur-type",
-                                                           "Année de mise en service du parc"))),
-                          class = "numeric",
-                          rows = list(names = TRUE),
-                          cols = list(names = TRUE)),
+              {conditionalPanel("output.hide_fatalities",
+                                br(),
+
+                                {wellPanel(style = "background:#F0F8FF",
+
+                                           radioButtons(inputId = "fatalities_input_type",
+                                                        label = "Type de saisie",
+                                                        choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")),
+
+                                           # Values
+                                           numericInput(inputId = "fatalities_mean",
+                                                        label = "Moyenne des mortalités annuelles",
+                                                        value = 5,
+                                                        min = 0, max = Inf, step = 0.5),
+                                           numericInput(inputId = "fatalities_se",
+                                                        label = "Erreur-type des mortalités annuelles",
+                                                        value = 0.05,
+                                                        min = 0, max = Inf, step = 0.1),
+
+                                           # Matrix for expert elicitation
+                                           matrixInput(inputId = "fatalities_mat_expert",
+                                                       value = matrix(data = eli_fatalities, nrow = 4, ncol = 5,
+                                                                      dimnames = list(c("#1", "#2", "#3", "#4"),
+                                                                                      c("Poids", "Min", "Best", "Max", "% IC" )),
+                                                                      byrow = TRUE),
+                                                       class = "numeric",
+                                                       rows = list(names = TRUE),
+                                                       cols = list(names = TRUE)),
+
+                                           actionButton(inputId = "fatalities_run_expert", label = "Utiliser valeurs experts"),
+
+                                           ### Part for cumulated impacts
+
+                                           numericInput(inputId = "farm_number_cumulated",
+                                                        label = "Nombre de parcs éoliens",
+                                                        value = 3, min = 2, max = Inf, step = 1),
+
+                                           matrixInput(inputId = "fatalities_mat_cumulated",
+                                                       value = matrix(init_cumul, 3, 3,
+                                                                      dimnames = list(c(paste0("Parc n°", c(1:3))),
+                                                                                      c("Moyenne",
+                                                                                        "Erreur-type",
+                                                                                        "Année de mise en service du parc"))),
+                                                       class = "numeric",
+                                                       rows = list(names = TRUE),
+                                                       cols = list(names = TRUE)),
+                                )}, # close wellPanel
+
+              )}, # close conditional panel
 
       )}, # end column "mortalité"
 
@@ -203,45 +209,49 @@ rm(list = ls(all.names = TRUE))
       {column(width = 3,
 
               tags$style(HTML('#button_pop_size{background-color:#C2C8D3}')),
-              actionButton(inputId = "button_pop_size",
+              actionButton(inputId = "button_pop_size", width = '100%',
                            label = tags$span("Taille de la population", style = "font-weight: bold; font-size: 18px;")
               ),
 
-              br(""),
+              {conditionalPanel("output.hide_pop_size",
+                              br(),
 
-              conditionalPanel("output.hide_pop_size",
-                               wellPanel(style = "background:#FFF8DC",
+                              {wellPanel(style = "background:#FFF8DC",
                                  radioButtons(inputId = "pop_size_unit", inline = TRUE,
                                               label = "Unité",
                                               choices = c("Nombre de couple" = "Npair", "Effectif total" = "Ntotal"),
                                               selected = "Ntotal"),
-                               ),
-              ),
+                              )}, # close wellPanel 1
 
-              radioButtons(inputId = "pop_size_input_type",
-                           label = "Type de saisie",
-                           choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")),
-
-              numericInput(inputId = "pop_size_mean",
-                           label = "Moyenne de la taille de la population",
-                           value = 200,
-                           min = 0, max = Inf, step = 50),
-
-              numericInput(inputId = "pop_size_se",
-                           label = "Erreur-type de la taille de la population",
-                           value = 25,
-                           min = 0, max = Inf, step = 1),
-
-              matrixInput(inputId = "pop_size_mat_expert",
-                          value = matrix(data = eli_pop_size, nrow = 4, ncol = 5,
-                                         dimnames = list(c("#1", "#2", "#3", "#4"),
-                                                         c("Poids", "Min", "Best", "Max", "% IC" )),
-                                         byrow = TRUE),
-                          class = "numeric",
-                          rows = list(names = TRUE),
-                          cols = list(names = TRUE)),
+                              {wellPanel(style = "background:#F0F8FF",
+
+                                         radioButtons(inputId = "pop_size_input_type",
+                                                      label = "Type de saisie",
+                                                      choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")),
+
+                                         numericInput(inputId = "pop_size_mean",
+                                                      label = "Moyenne de la taille de la population",
+                                                      value = 200,
+                                                      min = 0, max = Inf, step = 50),
+
+                                         numericInput(inputId = "pop_size_se",
+                                                      label = "Erreur-type de la taille de la population",
+                                                      value = 25,
+                                                      min = 0, max = Inf, step = 1),
 
-              actionButton(inputId = "pop_size_run_expert", label = "Utiliser valeurs experts"),
+                                         matrixInput(inputId = "pop_size_mat_expert",
+                                                     value = matrix(data = eli_pop_size, nrow = 4, ncol = 5,
+                                                                    dimnames = list(c("#1", "#2", "#3", "#4"),
+                                                                                    c("Poids", "Min", "Best", "Max", "% IC" )),
+                                                                    byrow = TRUE),
+                                                     class = "numeric",
+                                                     rows = list(names = TRUE),
+                                                     cols = list(names = TRUE)),
+
+                                         actionButton(inputId = "pop_size_run_expert", label = "Utiliser valeurs experts"),
+                              )}, # close wellPanel 2
+
+              )}, # close conditional panel
 
       )}, # end column "mortalité"
       ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~###
@@ -252,46 +262,55 @@ rm(list = ls(all.names = TRUE))
       ##~~~~~~~~~~~~~~~~~~~~~~~~~
       {column(width = 3,
 
-              tags$style(HTML('#button_pop_trend{background-color:#C2C8D3}')),
-              actionButton(inputId = "button_pop_trend",
+              tags$style(HTML('#button_pop_growth{background-color:#C2C8D3}')),
+              actionButton(inputId = "button_pop_growth", width = '100%',
                            label = tags$span("Tendance de la population", style = "font-weight: bold; font-size: 18px;")
               ),
 
-              br(""),
-              radioButtons(inputId = "pop_growth_input_type",
-                           label = "Type de saisie",
-                           choices = c("Taux de croissance" = "val",
-                                       "Elicitation d'expert" = "eli_exp",
-                                       "Tendance locale ou régionale" = "trend")),
-
-              numericInput(inputId = "pop_growth_mean",
-                           label = "Moyenne de la croissance de la population",
-                           value = 1.1,
-                           min = 0, max = Inf, step = 0.01),
-
-              numericInput(inputId = "pop_growth_se",
-                           label = "Erreur-type de la croissance de la population",
-                           value = 0.01,
-                           min = 0, max = Inf, step = 0.01),
-
-              matrixInput(inputId = "pop_growth_mat_expert",
-                          value = matrix(data = eli_pop_growth, nrow = 4, ncol = 5,
-                                         dimnames = list(c("#1", "#2", "#3", "#4"),
-                                                         c("Poids", "Min", "Best", "Max", "% IC" )),
-                                         byrow = TRUE),
-                          class = "numeric",
-                          rows = list(names = TRUE),
-                          cols = list(names = TRUE)),
+              {conditionalPanel("output.hide_pop_growth",
+                                br(),
 
-              actionButton(inputId = "pop_growth_run_expert", label = "Utiliser valeurs experts"),
+                                {wellPanel(style = "background:#F0F8FF",
 
-              radioButtons(inputId = "pop_trend",
-                           label = NULL,
-                           choices = c("Croissance", "Stable", "Déclin")),
+                                           radioButtons(inputId = "pop_growth_input_type",
+                                                        label = "Type de saisie",
+                                                        choices = c("Taux de croissance" = "val",
+                                                                    "Elicitation d'expert" = "eli_exp",
+                                                                    "Tendance locale ou régionale" = "trend")),
+
+                                           numericInput(inputId = "pop_growth_mean",
+                                                        label = "Moyenne de la croissance de la population",
+                                                        value = 1.1,
+                                                        min = 0, max = Inf, step = 0.01),
+
+                                           numericInput(inputId = "pop_growth_se",
+                                                        label = "Erreur-type de la croissance de la population",
+                                                        value = 0.01,
+                                                        min = 0, max = Inf, step = 0.01),
+
+                                           matrixInput(inputId = "pop_growth_mat_expert",
+                                                       value = matrix(data = eli_pop_growth, nrow = 4, ncol = 5,
+                                                                      dimnames = list(c("#1", "#2", "#3", "#4"),
+                                                                                      c("Poids", "Min", "Best", "Max", "% IC" )),
+                                                                      byrow = TRUE),
+                                                       class = "numeric",
+                                                       rows = list(names = TRUE),
+                                                       cols = list(names = TRUE)),
+
+                                           actionButton(inputId = "pop_growth_run_expert", label = "Utiliser valeurs experts"),
+
+                                           radioButtons(inputId = "pop_trend",
+                                                        label = NULL,
+                                                        choices = c("Croissance", "Stable", "Déclin")),
+
+                                           radioButtons(inputId = "pop_trend_strength",
+                                                        label = NULL,
+                                                        choices = c("Faible", "Moyen", "Fort")),
+
+                                )}, # close wellPanel
+
+              )}, # close conditional panel
 
-              radioButtons(inputId = "pop_trend_strength",
-                           label = NULL,
-                           choices = c("Faible", "Moyen", "Fort")),
       )}, # end column "mortalité"
       ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~###
 
@@ -302,30 +321,43 @@ rm(list = ls(all.names = TRUE))
       {column(width = 3,
 
               tags$style(HTML('#button_carrying_cap{background-color:#C2C8D3}')),
-              actionButton(inputId = "button_carrying_cap",
+              actionButton(inputId = "button_carrying_cap", width = '100%',
                            label = tags$span("Capacité de charge", style = "font-weight: bold; font-size: 18px;")
               ),
 
-              br(""),
-              radioButtons(inputId = "carrying_cap_input_type",
-                           label = "Type de saisie",
-                           choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")),
-
-              numericInput(inputId = "carrying_capacity",
-                           label = "Capacité de charge",
-                           value = 500,
-                           min = 0, max = Inf, step = 100),
-
-              matrixInput(inputId = "carrying_cap_mat_expert",
-                          value = matrix(data = eli_carrying_cap, nrow = 4, ncol = 5,
-                                         dimnames = list(c("#1", "#2", "#3", "#4"),
-                                                         c("Poids", "Min", "Best", "Max", "% IC" )),
-                                         byrow = TRUE),
-                          class = "numeric",
-                          rows = list(names = TRUE),
-                          cols = list(names = TRUE)),
+              {conditionalPanel("output.hide_carrying_cap",
+                                br(),
+
+                                {wellPanel(style = "background:#FFF8DC",
+                                           span(textOutput(outputId = "carrying_cap_unit_info"), style="font-size:16px"),
+
+                                )}, # close wellPanel 1
+
+                                {wellPanel(style = "background:#F0F8FF",
+
+                                           radioButtons(inputId = "carrying_cap_input_type",
+                                                        label = "Type de saisie",
+                                                        choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")),
+
+                                           numericInput(inputId = "carrying_capacity",
+                                                        label = "Capacité de charge",
+                                                        value = 500,
+                                                        min = 0, max = Inf, step = 100),
+
+                                           matrixInput(inputId = "carrying_cap_mat_expert",
+                                                       value = matrix(data = eli_carrying_cap, nrow = 4, ncol = 5,
+                                                                      dimnames = list(c("#1", "#2", "#3", "#4"),
+                                                                                      c("Poids", "Min", "Best", "Max", "% IC" )),
+                                                                      byrow = TRUE),
+                                                       class = "numeric",
+                                                       rows = list(names = TRUE),
+                                                       cols = list(names = TRUE)),
+
+                                           actionButton(inputId = "carrying_cap_run_expert", label = "Utiliser valeurs experts"),
+
+                                )}, # close wellPanel 2
 
-              actionButton(inputId = "carrying_cap_run_expert", label = "Utiliser valeurs experts"),
+              )}, # close conditional panel
 
       )}, # end column "mortalité"
       ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~###
-- 
GitLab