Skip to content
Snippets Groups Projects
server.R 73.5 KiB
Newer Older
        V2 <- NULL
      }

      if(input$pop_trend == "growth"){
        V1 <- "En croissance"
        if(input$pop_trend_strength == "weak") V2 <- "faible"
        if(input$pop_trend_strength == "average") V2 <- "modre"
        if(input$pop_trend_strength == "strong") V2 <- "forte"
      }

      if(input$pop_trend == "decline"){
        V1 <- "En dclin"
        if(input$pop_trend_strength == "weak") V2 <- "faible"
        if(input$pop_trend_strength == "average") V2 <- "modr"
        if(input$pop_trend_strength == "strong") V2 <- "fort"
      }
        out$pop_growth_val1 <- V1
        out$pop_growth_val2 <- V2
    }

  })

  # Carrying capacity
  observeEvent({
    input$run
  }, {
    if(input$pop_size_unit == "Npair"){
      out$carrying_cap_unit <- paste0("Unit : nombre de couples")
      unit <- " couples"
    }
    if(input$pop_size_unit == "Ntotal"){
      out$carrying_cap_unit <- paste0("Unit : effectif total")
      unit <- " individus"
    }

    if(input$carrying_cap_input_type == "itvl"){
      out$carrying_cap_input_type <- "Saisie : intervalle"
      out$carrying_cap_val1 <- paste0("Min : ", input$carrying_capacity_lower, unit, " ; ")
      out$carrying_cap_val2 <- paste0("Max : ", input$carrying_capacity_upper, unit)
    }
    if(input$carrying_cap_input_type == "val"){
      out$carrying_cap_input_type <- "Saisie : estimation et erreur-type"
      out$carrying_cap_val1 <- paste0("Valeur estime : ", input$carrying_capacity_mean, unit, " ; ")
      out$carrying_cap_val2 <- paste0("Erreur-type : ", input$carrying_capacity_se, unit)
    }
    if(input$carrying_cap_input_type == "eli_exp"){
      out$carrying_cap_input_type <- "Saisie : licitation d'experts"
      out$carrying_cap_val1 <- paste0("Moyenne estime : ", round(param$carrying_cap_eli_result$mean, 2), unit, " ; ")
      out$carrying_cap_val2 <- paste0("Erreur_type : ", round(param$carrying_cap_eli_result$SE, 2), unit)
    }

    if(input$carrying_cap_input_type == "no_K"){
      out$carrying_cap_input_type <- NULL
      out$carrying_cap_val1 <- paste0("Absence de capacit de charge")
      out$carrying_cap_val2 <- paste0("Justifi ou pas ??")
    }

  })


  ## Results

  # Graphs
  observeEvent({
    input$run
  }, {
    out$impact_plot <- plot_out_impact(legend_position = "bottom", text_size = "small")
  })




  ###################################################################################

  ##-----------------------------------------------------------------------------------
  ##                                REPORT
  ##-----------------------------------------------------------------------------------
  output$report <- downloadHandler(

    filename = "RapportEolpopTEST001.pdf",

    content = function(file) {
      # Copy the report file to a temporary directory before processing it, in
      # case we don't have write permissions to the current working dir (which
      # can happen when deployed).
      tempReport <- file.path(tempdir(), "report.Rmd")

      file.copy("./inst/ShinyApp/report.Rmd", tempReport, overwrite = TRUE)

      # Set up parameters to pass to Rmd document
      paramsRMD <- list(
        intro = input$intro_report,
        analysis = out$analysis_choice_report,
        species = out$species_choice,
        def_pop_text = input$def_pop_text,
        #vital_rates = out$vital_rates,
        fatalities_unit = out$fatalities_unit,
        fatalities_input_type = out$fatalities_input_type,
        fatalities_val1 = out$fatalities_val1,
        fatalities_val2 = out$fatalities_val2,

        pop_size_unit = out$pop_size_unit,
        pop_size_input_type = out$pop_size_input_type,
        pop_size_val1 = out$pop_size_val1,
        pop_size_val2 = out$pop_size_val2,
        pop_growth_input_type = out$pop_growth_input_type,
        pop_growth_val1 = out$pop_growth_val1,
        pop_growth_val2 = out$pop_growth_val2,
        carrying_cap_unit = out$carrying_cap_unit,
        carrying_cap_input_type = out$carrying_cap_input_type,
        carrying_cap_val1 = out$carrying_cap_val1,
        carrying_cap_val2 = out$carrying_cap_val2,
        impact_plot = out$impact_plot,
        trajectory_plot = out$trajectory_plot
        )


      # Knit the document, passing in the `params` list, and eval it in a
      # child of the global environment (this isolates the code in the document
      # from the code in this app).
      rmarkdown::render(tempReport, output_file = file,
                        params = paramsRMD,
                        envir = new.env(parent = globalenv())
      )
    }
  ) # close downloadHandler


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