Skip to content
Snippets Groups Projects
Commit cc638834 authored by thierrychambert's avatar thierrychambert
Browse files

Shiny : added text output (impact as %)

parent 2f1667fe
No related branches found
No related tags found
No related merge requests found
...@@ -196,8 +196,10 @@ server <- function(input, output, session){ ...@@ -196,8 +196,10 @@ server <- function(input, output, session){
##-------------------------------------------- ##--------------------------------------------
## Reactive value : simulation inputs ## Reactive value
##-------------------------------------------- ##--------------------------------------------
out <- reactiveValues(run = NULL)
param <- reactiveValues(N1 = NULL, param <- reactiveValues(N1 = NULL,
nsim = NULL, nsim = NULL,
cumulated_impacts = NULL, cumulated_impacts = NULL,
...@@ -681,7 +683,7 @@ server <- function(input, output, session){ ...@@ -681,7 +683,7 @@ server <- function(input, output, session){
withProgress(message = 'Simulation progress', value = 0, { withProgress(message = 'Simulation progress', value = 0, {
param$N1 <- run_simul_shiny(nsim = param$nsim, out$run <- run_simul_shiny(nsim = param$nsim,
cumulated_impacts = param$cumulated_impacts, cumulated_impacts = param$cumulated_impacts,
fatalities_mean = param$fatalities_mean, fatalities_mean = param$fatalities_mean,
...@@ -710,26 +712,63 @@ server <- function(input, output, session){ ...@@ -710,26 +712,63 @@ server <- function(input, output, session){
}) # Close observEvent }) # Close observEvent
# Plot Impacts
##--------------------------------------------------------------------------##
## OUTPUTS
##--------------------------------------------------------------------------##
##--------------------------------------------
# Show result : impact text
##--------------------------------------------
## Two Functions to print the output
# print_it
print_it <- function(impact, lci, uci){
paste0("Impact sur la taille de population : ", round(impact, 2)*100, "%",
"[", round(lci, 2)*100, "% ; ", round(uci, 2)*100, "%]")
}
# print_out
print_out <- function() if(is.null(out$run$N)) {} else {
print_it(impact = get_metrics(N = out$run$N)$scenario$impact[time_horzion, "avg",-1],
lci = get_metrics(N = out$run$N)$scenario$impact[time_horzion, "lci",-1],
uci = get_metrics(N = out$run$N)$scenario$impact[time_horzion, "uci",-1])
}
# Display result (text)
output$impact_text <- renderText({ print_out() })
# Plot Impacts
plot_out_impact <- function(){ plot_out_impact <- function(){
if(is.null(param$N1)) {} else {plot_impact(N = param$N1$N, xlab = "year", ylab = "pop size")} if(is.null(out$run)) {} else {plot_impact(N = out$run$N, xlab = "year", ylab = "pop size")}
} }
output$graph_impact <- renderPlot({ output$title_impact_plot <- renderText({
if(input$run > 0){
"Rsultat : Impact relatif au cours du temps"
}
})
output$impact_plot <- renderPlot({
plot_out_impact() plot_out_impact()
}) })
# Plot trajectories # Plot trajectories
plot_out_traj <- function(){ plot_out_traj <- function(){
if(is.null(param$N1)) {} else {plot_traj(N = param$N1$N, xlab = "year", ylab = "pop size")} if(is.null(out$run)) {} else {plot_traj(N = out$run$N, xlab = "year", ylab = "pop size")}
} }
output$graph_traj <- renderPlot({ output$graph_traj <- renderPlot({
plot_out_traj() plot_out_traj()
}) })
# End simulations
##-------------------------------------------- ##--------------------------------------------
......
...@@ -446,25 +446,28 @@ rm(list = ls(all.names = TRUE)) ...@@ -446,25 +446,28 @@ rm(list = ls(all.names = TRUE))
tabPanel(title = "Impact population", tabPanel(title = "Impact population",
br(""), br(),
numericInput(inputId = "nsim", label = "Nombre de simulations", numericInput(inputId = "nsim",
label = "Nombre de simulations",
value = 10, min = 0, max = Inf, step = 10), value = 10, min = 0, max = Inf, step = 10),
radioButtons(inputId = "fatal_constant", radioButtons(inputId = "fatal_constant",
label = h4("Modlisation"), label = "Modlisation",
choices = c("Taux de mortalits (h) constant" = "h", choices = c("Taux de mortalits (h) constant" = "h",
"Nombre de mortalits (M) constant" = "M")), "Nombre de mortalits (M) constant" = "M")),
br(), br(),
strong(span(textOutput("message"), style="color:blue; font-size:24px", align = "center")), strong(span(textOutput("impact_text"), style="color:blue; font-size:24px", align = "left")),
br(), br(),
actionButton(inputId = "run", label = "Lancer l'analyse"), actionButton(inputId = "run", label = "Lancer l'analyse"),
hr(), hr(),
h4("Graphique : Impact relatif de chaque scnario", align = "center"),
plotOutput("graph_impact", width = "100%", height = "550px"), tags$h4(textOutput("title_impact_plot"), align = "center"),
plotOutput("impact_plot", width = "100%", height = "550px"),
hr(), hr(),
h4("Graphique : Trajectoire dmographique", align = "center"), h4("Graphique : Trajectoire dmographique", align = "center"),
plotOutput("graph_traj", width = "100%", height = "550px") plotOutput("graph_traj", width = "100%", height = "550px")
), # End tabPanel ), # End tabPanel
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment