Skip to content
Snippets Groups Projects
server.R 66.8 KiB
Newer Older
Marie-Bocage's avatar
Marie-Bocage committed
server <- function(input, output, session){
Marie-Bocage's avatar
Marie-Bocage committed


  ###################################################
  ##  Fixed parameters in the server environment
  ##-------------------------------------------------
  ## Load species list
  species_data <- read.csv("./inst/ShinyApp/species_list.csv", sep = ",")

  ## Load survival and fecundities data
  data_sf <- read.csv("./inst/ShinyApp/survivals_fecundities_species.csv", sep = ",")#, encoding = "UTF-8")

  # We define theta = 1 (same as in PBR) - for simplicity, given large uncertainty of real shape of density-dependence in nature
  fixed_theta = 1

  # Coefficient of environmental variation (SD)
  ## Environnmental variance set at 8%, based on values found for birds in the literature:
  ## (Saeher & Engen 2002) : between 7% et 14 ==> average : 10%
  ## (Sther et al. 2005) : between 2.5% et 10% ==> average : 6%
  coeff_var_environ = sqrt(0.08) # SD ~28%

  # Coverage probability used for lower/upper interval input values
  CP = 0.99

  # Values of pop_growth (assumed), when the "trend" option is chosen
  growth_weak <- 1.05
  growth_average <- 1.10
  growth_strong <- 1.15

  decline_weak <- 0.97
  decline_average <- 0.94
  decline_strong <- 0.91

  pop_stable <- 1
  trend_se <- 0.05 # SE to use for pop_growth, when the "trend" option is chosen


  ##############################################
thierrychambert's avatar
thierrychambert committed
  ##--------------------------------------------

  ## 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
thierrychambert's avatar
thierrychambert committed
  output$hide_pop_size <- eventReactive({
    input$button_pop_size
  },{
    if(input$button_pop_size%%2 == 1) TRUE else FALSE
  }, ignoreInit = TRUE)

  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")
    }
  })


  ## Outputs / Results
  output$hide_results <- eventReactive({
    input$run
  },{
    if(input$run > 0) TRUE else FALSE
  }, ignoreInit = TRUE)

  outputOptions(output, "hide_results", suspendWhenHidden = FALSE)


  ##############################################
thierrychambert's avatar
thierrychambert committed
  ##--------------------------------------------
thierrychambert's avatar
thierrychambert committed
  observe({
    shinyjs::hide("fatalities_mean")
    shinyjs::hide("fatalities_se")
    shinyjs::hide("fatalities_lower")
    shinyjs::hide("fatalities_upper")
    shinyjs::hide("fatalities_number_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("fatalities_mat_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("fatalities_run_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("farm_number_cumulated")
    shinyjs::hide("fatalities_mat_cumulated")
    shinyjs::hide("fatalities_vec_scenario")
    shinyjs::hide("pop_size_lower")
    shinyjs::hide("pop_size_upper")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("pop_size_mean")
    shinyjs::hide("pop_size_se")
    shinyjs::hide("pop_size_number_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("pop_size_mat_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("pop_size_run_expert")
    shinyjs::hide("pop_growth_lower")
    shinyjs::hide("pop_growth_upper")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("pop_growth_mean")
    shinyjs::hide("pop_growth_se")
    shinyjs::hide("pop_growth_number_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("pop_growth_mat_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("pop_growth_run_expert")
Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("pop_trend")
    shinyjs::hide("pop_trend_strength")
    shinyjs::hide("carrying_capacity_lower")
    shinyjs::hide("carrying_capacity_upper")
    shinyjs::hide("carrying_capacity_mean")
    shinyjs::hide("carrying_capacity_se")
    shinyjs::hide("carrying_cap_number_expert")
    shinyjs::hide("carrying_cap_mat_expert")
    shinyjs::hide("carrying_cap_run_expert")

Marie-Bocage's avatar
Marie-Bocage committed
    shinyjs::hide("mat_fill_vr")
    shinyjs::hide("vr_mat_number_age_classes")
Marie-Bocage's avatar
Marie-Bocage committed

    #------------
    # Show some
    #------------
    # Show inputs for fatalities part
Marie-Bocage's avatar
Marie-Bocage committed
    if(input$button_fatalities%%2 == 1){
thierrychambert's avatar
thierrychambert committed
      #shinyjs::show("fatal_constant")
Marie-Bocage's avatar
Marie-Bocage committed

      # Show inputs for single farm option (non-cumulated impacts)
      if(input$analysis_choice == "single_farm"){
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("fatalities_input_type")
        if(input$fatalities_input_type == "itvl"){
          shinyjs::show("fatalities_lower")
          shinyjs::show("fatalities_upper")
Marie-Bocage's avatar
Marie-Bocage committed
        }
        if(input$fatalities_input_type == "val"){
          shinyjs::show("fatalities_mean")
          shinyjs::show("fatalities_se")
        }
thierrychambert's avatar
thierrychambert committed
        if(input$fatalities_input_type == "eli_exp"){
          shinyjs::show("fatalities_number_expert")
Marie-Bocage's avatar
Marie-Bocage committed
          shinyjs::show("fatalities_mat_expert")
Marie-Bocage's avatar
Marie-Bocage committed
          shinyjs::show("fatalities_run_expert")
      # Show inputs for cumulated impacts option
Marie-Bocage's avatar
Marie-Bocage committed
      if(input$analysis_choice == "cumulated"){
        shinyjs::hide("fatalities_input_type")
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("farm_number_cumulated")
        shinyjs::show("fatalities_mat_cumulated")
thierrychambert's avatar
thierrychambert committed
      }
Marie-Bocage's avatar
Marie-Bocage committed

      # Show inputs for multiple scenario
      if(input$analysis_choice == "multi_scenario"){
        shinyjs::hide("fatalities_input_type")
        shinyjs::show("fatalities_vec_scenario")
      }

Marie-Bocage's avatar
Marie-Bocage committed
    # Show inputs for population size part
    if(input$button_pop_size%%2 == 1){
      shinyjs::show("pop_size_input_type")
      if(input$pop_size_input_type == "itvl"){
        shinyjs::show("pop_size_lower")
        shinyjs::show("pop_size_upper")
      }
thierrychambert's avatar
thierrychambert committed
      if(input$pop_size_input_type == "val"){
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("pop_size_mean")
        shinyjs::show("pop_size_se")
      }
thierrychambert's avatar
thierrychambert committed
      if(input$pop_size_input_type == "eli_exp"){
        shinyjs::show("pop_size_number_expert")
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("pop_size_mat_expert")
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("pop_size_run_expert")
    # Show inputs for population trend/growth part
    if(input$button_pop_growth%%2 == 1){
      shinyjs::show("pop_growth_input_type")

      if(input$pop_growth_input_type == "itvl"){
        shinyjs::show("pop_growth_lower")
        shinyjs::show("pop_growth_upper")
      }
thierrychambert's avatar
thierrychambert committed
      if(input$pop_growth_input_type == "val"){
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("pop_growth_mean")
        shinyjs::show("pop_growth_se")
      }
thierrychambert's avatar
thierrychambert committed
      if(input$pop_growth_input_type == "eli_exp"){
        shinyjs::show("pop_growth_number_expert")
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("pop_growth_mat_expert")
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("pop_growth_run_expert")
Marie-Bocage's avatar
Marie-Bocage committed
      }
thierrychambert's avatar
thierrychambert committed
      if(input$pop_growth_input_type == "trend"){
Marie-Bocage's avatar
Marie-Bocage committed
        shinyjs::show("pop_trend")
thierrychambert's avatar
Loading
Loading full blame...