From 55c7dae61456f53fcd7d627b4612a2af01608451 Mon Sep 17 00:00:00 2001
From: thierrychambert <thierry.chambert@gmail.com>
Date: Fri, 13 Aug 2021 16:43:21 +0200
Subject: [PATCH] Fixed some issue

Added observe(param) in server to make sure param used in simulations keep up to date !
---
 inst/ShinyApp/runApp.R |  1 +
 inst/ShinyApp/server.R | 23 +++++++++++++----------
 inst/ShinyApp/ui.R     |  7 ++++---
 run_analysis.R         |  1 +
 4 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/inst/ShinyApp/runApp.R b/inst/ShinyApp/runApp.R
index 266fa21..01caab2 100644
--- a/inst/ShinyApp/runApp.R
+++ b/inst/ShinyApp/runApp.R
@@ -1,3 +1,4 @@
+library(eolpop)
 source("./inst/ShinyApp/ui.R")
 source("./inst/ShinyApp/server.R")
 
diff --git a/inst/ShinyApp/server.R b/inst/ShinyApp/server.R
index d2dd703..981b865 100644
--- a/inst/ShinyApp/server.R
+++ b/inst/ShinyApp/server.R
@@ -157,6 +157,7 @@ server <- function(input, output, session){
                           carrying_cap_eli_result = NULL)
   ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~###
 
+  observe(param)
 
   ##--------------------------------------------
   ##  Display parameter distribution          --
@@ -192,7 +193,6 @@ server <- function(input, output, session){
   ##  Run expert elicitation                  --
   ##--------------------------------------------
   plot_expert <- function(out, show_se = TRUE, ...){
-    #plot_elicitation(out, ylab = "Densité de probabilité", xlab = "Valeur du paramètre", cex.lab = 1.2)
     plot_elicitation(out, ylab = "", xlab = "Valeur du paramètre", cex.lab = 1.2, yaxt = "n")
     mtext(text = "Densité de probabilité", side = 2, line = 2, cex = 1.2)
 
@@ -353,6 +353,17 @@ server <- function(input, output, session){
   })
 
 
+  ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
+  ## Survivals, fecundities and rMAX_species ###~~~~~~~~~~~~~~~~~~~~~~~~~~###
+  observeEvent({input$run}, {
+    param$survivals <- input$mat_fill_vr[,1]
+    param$fecundities <- input$mat_fill_vr[,2]
+    param$rMAX_species <- rMAX_spp(surv = tail(param$survivals,1), afr = min(which(param$fecundities != 0)))
+  }) # end observeEvent
+
+
+
+
   ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
   ## Population growth ###~~~~~~~~~~~~~~~~~~~~~~~~~~###
   observeEvent({
@@ -399,14 +410,6 @@ server <- function(input, output, session){
     }
   })
 
-  # Survivals and fecundities
-  observeEvent({input$run}, {
-      param$survivals <- input$mat_fill_vr[,1]
-      param$fecundities <- input$mat_fill_vr[,2]
-      param$rMAX_species <- rMAX_spp(surv = tail(param$survivals,1), afr = min(which(param$fecundities != 0)))
-  }) # end observeEvent
-
-
   # Survival and fecundity calibration
   observeEvent({
     input$run
@@ -466,7 +469,7 @@ server <- function(input, output, session){
                                   fecundities = param$f_calibrated,
 
                                   carrying_capacity = param$carrying_capacity,
-                                  theta = param$theta,
+                                  theta = theta,
                                   rMAX_species = param$rMAX_species,
 
                                   model_demo = NULL,
diff --git a/inst/ShinyApp/ui.R b/inst/ShinyApp/ui.R
index d0da8bc..6d38db5 100644
--- a/inst/ShinyApp/ui.R
+++ b/inst/ShinyApp/ui.R
@@ -219,7 +219,8 @@ ui <- fluidPage(
 
       radioButtons(inputId = "pop_size_type",
                    label = h4("Unité"),
-                   choices = c("Nombre de couple" = "Npair", "Effectif total" = "Ntotal")),
+                   choices = c("Nombre de couple" = "Npair", "Effectif total" = "Ntotal"),
+                   selected = "Ntotal"),
 
       radioButtons(inputId = "pop_size_input_type",
                    label = h4("Type de saisie"),
@@ -265,7 +266,7 @@ ui <- fluidPage(
 
       numericInput(inputId = "pop_growth_mean",
                    label = "Moyenne de la croissance de la population",
-                   value = 1,
+                   value = 1.1,
                    min = 0, max = Inf, step = 0.01),
 
       numericInput(inputId = "pop_growth_se",
@@ -311,7 +312,7 @@ ui <- fluidPage(
 
       numericInput(inputId = "carrying_capacity",
                    label = "Capacité de charge",
-                   value = 1000,
+                   value = 500,
                    min = 0, max = Inf, step = 100),
 
       matrixInput(inputId = "carrying_cap_mat_expert",
diff --git a/run_analysis.R b/run_analysis.R
index 1b4a70e..affe7bd 100644
--- a/run_analysis.R
+++ b/run_analysis.R
@@ -69,6 +69,7 @@ lambda( build_Leslie(s = s_calibrated, f = f_calibrated) )
 #fatal_constant = "M"
 #cumulated_impacts = FALSE
 
+pop_growth_mean = 1.1
 pop_size_type = "Ntotal"
 carrying_capacity = 500
 
-- 
GitLab