diff --git a/inst/ShinyApp/server.R b/inst/ShinyApp/server.R index 9f2f3fabee3a2e8650e95a6b7c07684faa412bd8..d2dd7033044af21f860c07e113765906505d7beb 100644 --- a/inst/ShinyApp/server.R +++ b/inst/ShinyApp/server.R @@ -41,11 +41,11 @@ server <- function(input, output, session){ if(input$analysis_choice == "scenario"){ shinyjs::show("fatalities_input_type") - if(input$fatalities_input_type == "Valeurs"){ + if(input$fatalities_input_type == "val"){ shinyjs::show("fatalities_mean") shinyjs::show("fatalities_se") } - if(input$fatalities_input_type == "Elicitation d'expert"){ + if(input$fatalities_input_type == "eli_exp"){ shinyjs::show("fatalities_mat_expert") shinyjs::show("fatalities_run_expert") } @@ -65,11 +65,11 @@ server <- function(input, output, session){ if(input$button_pop_size%%2 == 1){ shinyjs::show("pop_size_type") shinyjs::show("pop_size_input_type") - if(input$pop_size_input_type == "Valeurs"){ + if(input$pop_size_input_type == "val"){ shinyjs::show("pop_size_mean") shinyjs::show("pop_size_se") } - if(input$pop_size_input_type == "Elicitation d'expert"){ + if(input$pop_size_input_type == "eli_exp"){ shinyjs::show("pop_size_mat_expert") shinyjs::show("pop_size_run_expert") } @@ -79,10 +79,10 @@ server <- function(input, output, session){ if(input$button_carrying_cap%%2 == 1){ shinyjs::show("carrying_cap_input_type") - if(input$carrying_cap_input_type == "Valeurs"){ + if(input$carrying_cap_input_type == "val"){ shinyjs::show("carrying_capacity") } - if(input$carrying_cap_input_type == "Elicitation d'expert"){ + if(input$carrying_cap_input_type == "eli_exp"){ shinyjs::show("carrying_cap_mat_expert") shinyjs::show("carrying_cap_run_expert") } @@ -92,15 +92,15 @@ server <- function(input, output, session){ if(input$button_pop_trend%%2 == 1){ shinyjs::show("pop_growth_input_type") - if(input$pop_growth_input_type == "Taux de croissance"){ + if(input$pop_growth_input_type == "val"){ shinyjs::show("pop_growth_mean") shinyjs::show("pop_growth_se") } - if(input$pop_growth_input_type == "Elicitation d'expert"){ + if(input$pop_growth_input_type == "eli_exp"){ shinyjs::show("pop_growth_mat_expert") shinyjs::show("pop_growth_run_expert") } - if(input$pop_growth_input_type == "Tendance locale ou régionale"){ + if(input$pop_growth_input_type == "trend"){ shinyjs::show("pop_trend") shinyjs::show("pop_trend_strength") } @@ -280,13 +280,11 @@ server <- function(input, output, session){ - - - ##-------------------------------------------- - ## Observe input and report values -- + ## Select parameter values for simulations -- ##-------------------------------------------- - ## Cumulated impacts or not ? + + ## Cumulated impacts or not ? ###~~~~~~~~~~~~~~~~~~~~~~~~~~### observeEvent({ input$run }, { @@ -298,19 +296,7 @@ server <- function(input, output, session){ }) # end observeEvent - - - - ### Plot distribution - - - - - - - ##-------------------------------------------- - ## Select parameter values for simulations -- - ##-------------------------------------------- + ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~### ## Fatalities ###~~~~~~~~~~~~~~~~~~~~~~~~~~### observeEvent({ input$run @@ -319,7 +305,7 @@ server <- function(input, output, session){ if(input$analysis_choice == "scenario"){ # Case 1.1 : Values from expert elicitation (if2) - if(input$fatalities_input_type == "Elicitation d'expert"){ + if(input$fatalities_input_type == "eli_exp"){ param$fatalities_mean <- c(0, round(param$fatalities_eli_result$mean)) param$onset_time <- NULL param$fatalities_se <- c(0, round(param$fatalities_eli_result$SE)) @@ -341,18 +327,24 @@ server <- function(input, output, session){ } # end (if1) }) # end observeEvent + ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~### + ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~### + ## Population size ###~~~~~~~~~~~~~~~~~~~~~~~~~~### + observeEvent({ + input$run + },{ - # Observe pop size value - ## Mean, se and type - observeEvent({input$run},{ - if(input$pop_size_input_type == "Elicitation d'expert"){ + # Case 1 : Values from expert elicitation + if(input$pop_size_input_type == "eli_exp"){ if(!(is.null(param$pop_size_eli_result))){ param$pop_size_mean <- round(param$pop_size_eli_result$mean) param$pop_size_se <- round(param$pop_size_eli_result$SE) } else { - print("#intégrer un message d'erreur") + print("Erreur: Vous n'avez pas lancer l'analyse 'valeurs experts'") } + + # Case 2 : Values directly provided (i.e., not from expert elicitation) } else { param$pop_size_mean <- input$pop_size_mean param$pop_size_se <- input$pop_size_se @@ -360,16 +352,25 @@ server <- function(input, output, session){ param$pop_size_type <- input$pop_size_type }) - # Observe pop growth value - observeEvent({input$run}, { - if(input$pop_growth_input_type == "Elicitation d'expert"){ + + ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~## + ## Population growth ###~~~~~~~~~~~~~~~~~~~~~~~~~~### + observeEvent({ + input$run + }, { + + # Case 1 : Values from expert elicitation + if(input$pop_growth_input_type == "eli_exp"){ if(!(is.null(param$pop_growth_eli_result))){ param$pop_growth_mean <- round(min(1 + param$rMAX_species, round(param$pop_growth_eli_result$mean, 2)), 2) param$pop_growth_se <- round(param$pop_growth_eli_result$SE, 2) } else { - print("#intégrer un message d'erreur") + print("Erreur: Vous n'avez pas lancer l'analyse 'valeurs experts'") } - } else if(input$pop_growth_input_type == "Tendance locale ou régionale"){ + + # Case 2 : Trend information + } else if(input$pop_growth_input_type == "trend"){ + if(input$pop_trend == "Croissance") { if(input$pop_trend_strength == "Faible") { param$pop_growth_mean <- 1.01 @@ -390,8 +391,9 @@ server <- function(input, output, session){ param$pop_growth_mean <- 1 } param$pop_growth_se <- 0.03 - } - else { + + # Case 3 : Values directly provided (i.e., not from expert elicitation) + } else { param$pop_growth_mean <- round(min(1 + param$rMAX_species, input$pop_growth_mean), 2) param$pop_growth_se <- input$pop_growth_se } @@ -420,7 +422,7 @@ server <- function(input, output, session){ # Observe carrying capacity observeEvent({input$run}, { - if(input$carrying_cap_input_type == "Elicitation d'expert"){ + if(input$carrying_cap_input_type == "eli_exp"){ if(!(is.null(param$carrying_cap_eli_result))){ param$carrying_capacity <- round(param$carrying_cap_eli_result$mean) } else { @@ -505,12 +507,13 @@ server <- function(input, output, session){ ## Fatalities - output$fatalities_mean_info <- renderText({ - if(input$fatalities_input_type == "Elicitation d'expert"){ + if(input$fatalities_input_type == "eli_exp"){ if(!(is.null(param$fatalities_eli_result))){ info <- round(param$fatalities_eli_result$mean, 2) - } else {info <- NA} + } else { + info <- NA + } } else { info <- input$fatalities_mean @@ -519,10 +522,12 @@ server <- function(input, output, session){ }) output$fatalities_se_info <- renderText({ - if(input$fatalities_input_type == "Elicitation d'expert"){ + if(input$fatalities_input_type == "eli_exp"){ if(!(is.null(param$fatalities_eli_result))){ - info <- round(param$fatalities_eli_result$SE) - } else {info <- NA} + info <- round(param$fatalities_eli_result$SE, 2) + } else { + info <- NA + } } else { info <- input$fatalities_se @@ -530,6 +535,15 @@ server <- function(input, output, session){ paste0("Erreur-type : ", info) }) + + + + + + + + + ## Poplutation size output$pop_size_type_info <- renderText({ @@ -541,7 +555,7 @@ server <- function(input, output, session){ }) output$pop_size_mean_info <- renderText({ - if(input$pop_size_input_type == "Elicitation d'expert"){ + if(input$pop_size_input_type == "eli_exp"){ if(!(is.null(param$pop_size_eli_result))){ info <- round(param$pop_size_eli_result$mean) } else {info <- NA} @@ -553,7 +567,7 @@ server <- function(input, output, session){ }) output$pop_size_se_info <- renderText({ - if(input$pop_size_input_type == "Elicitation d'expert"){ + if(input$pop_size_input_type == "eli_exp"){ if(!(is.null(param$pop_size_eli_result))){ info <- round(param$pop_size_eli_result$SE) } else {info <- NA} @@ -567,7 +581,7 @@ server <- function(input, output, session){ ## Carrying capacity output$carrying_capacity_info <- renderText({ - if(input$carrying_cap_input_type == "Elicitation d'expert"){ + if(input$carrying_cap_input_type == "eli_exp"){ if(!(is.null(param$carrying_cap_eli_result))){ info <- round(param$carrying_cap_eli_result$mean) } else {info <- NA} @@ -583,11 +597,11 @@ server <- function(input, output, session){ output$pop_trend_type_info <- renderText({paste0("Type de Tendance de pop : ", input$pop_growth_input_type)}) output$pop_growth_mean_info <- renderText({ - if(input$pop_growth_input_type == "Elicitation d'expert"){ + if(input$pop_growth_input_type == "eli_exp"){ if(!(is.null(param$pop_growth_eli_result))){ info <- round(param$pop_growth_eli_result$mean, 2) } else {info <- NA} - } else if(input$pop_growth_input_type == "Tendance locale ou régionale"){ + } else if(input$pop_growth_input_type == "trend"){ if(input$pop_trend == "Croissance") { if(input$pop_trend_strength == "Faible") { info <- 1.01 @@ -614,11 +628,11 @@ server <- function(input, output, session){ }) output$pop_growth_se_info <- renderText({ - if(input$pop_growth_input_type == "Elicitation d'expert"){ + if(input$pop_growth_input_type == "eli_exp"){ if(!(is.null(param$pop_growth_eli_result))){ info <- round(param$pop_growth_eli_result$SE, 2) } else {info <- NA} - } else if (input$pop_growth_input_type == "Tendance locale ou régionale") { + } else if (input$pop_growth_input_type == "trend") { info <- 0.03 } else { diff --git a/inst/ShinyApp/ui.R b/inst/ShinyApp/ui.R index 185512e855ee97f94d7148bb0a75597f4e59a63b..d0da8bc82f8ab63c277d4a4f5e68831236d42341 100644 --- a/inst/ShinyApp/ui.R +++ b/inst/ShinyApp/ui.R @@ -166,7 +166,7 @@ ui <- fluidPage( # Input type radioButtons(inputId = "fatalities_input_type", label = h4("Type de saisie"), - choices = c("Valeurs", "Elicitation d'expert")), + choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")), # Values numericInput(inputId = "fatalities_mean", @@ -223,7 +223,7 @@ ui <- fluidPage( radioButtons(inputId = "pop_size_input_type", label = h4("Type de saisie"), - choices = c("Valeurs", "Elicitation d'expert")), + choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")), numericInput(inputId = "pop_size_mean", label = "Moyenne de la taille de la population", @@ -259,7 +259,9 @@ ui <- fluidPage( radioButtons(inputId = "pop_growth_input_type", label = h4("Type de saisie"), - choices = c("Taux de croissance", "Elicitation d'expert", "Tendance locale ou régionale")), + 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", @@ -305,7 +307,7 @@ ui <- fluidPage( radioButtons(inputId = "carrying_cap_input_type", label = h4("Type de saisie"), - choices = c("Valeurs", "Elicitation d'expert")), + choices = c("Valeurs" = "val", "Elicitation d'expert" = "eli_exp")), numericInput(inputId = "carrying_capacity", label = "Capacité de charge", diff --git a/run_analysis.R b/run_analysis.R index 9a581d00f6340cb022834c74bfef28302c3ab3ba..1b4a70edb71e46aa401f53b0e9d6306f2ff18450 100644 --- a/run_analysis.R +++ b/run_analysis.R @@ -64,9 +64,11 @@ lambda( build_Leslie(s = s_calibrated, f = f_calibrated) ) -pop_size_mean = 200 -pop_growth_mean = 1.1 -fatal_constant = "M" +#pop_size_mean = 200 +#pop_growth_mean = 1.1 +#fatal_constant = "M" +#cumulated_impacts = FALSE + pop_size_type = "Ntotal" carrying_capacity = 500 @@ -74,16 +76,34 @@ carrying_capacity = 500 ##============================================================================== ## Analyses (simulations) == ##============================================================================== -run0 <- run_simul(nsim, cumulated_impacts, - fatalities_mean, fatalities_se, onset_time, - pop_size_mean, pop_size_se, pop_size_type, - pop_growth_mean, pop_growth_se, - survivals = s_calibrated, fecundities = f_calibrated, - carrying_capacity = carrying_capacity, theta = theta, - rMAX_species = rMAX_species, - model_demo, time_horzion, coeff_var_environ, fatal_constant) +run0 <- run_simul(nsim = nsim, + cumulated_impacts = cumulated_impacts, + + fatalities_mean = fatalities_mean, + fatalities_se = fatalities_se, + onset_time = onset_time, + + pop_size_mean = pop_size_mean, + pop_size_se = pop_size_se, + pop_size_type = pop_size_type, + + pop_growth_mean = pop_growth_mean, + pop_growth_se = pop_growth_se, + + survivals = s_calibrated, + fecundities = f_calibrated, + + carrying_capacity = carrying_capacity, + theta = theta, + rMAX_species = rMAX_species, + + model_demo = NULL, + time_horzion = time_horzion, + coeff_var_environ = coeff_var_environ, + fatal_constant = fatal_constant) +##################################################### names(run0)