diff --git a/inst/ShinyApp/server.R b/inst/ShinyApp/server.R index 8432874c7ce1827768279008b3ad275116d26a12..81c362d4fcf240067f383d770c0727779ecd7763 100644 --- a/inst/ShinyApp/server.R +++ b/inst/ShinyApp/server.R @@ -279,23 +279,18 @@ server <- function(input, output, session){ ############################################## ## Update matrix cumulated impact ##------------------------------------------- - observeEvent({input$farm_number_cumulated}, { - rows_names <- function(n){ - v <- c(paste0("Parc n°", c(1:n))) - return(v) - } - - nrow <- input$farm_number_cumulated - number_parks <- rows_names(nrow) - - init_cumul_new <- rep(init_cumul_add, nrow) + observeEvent({ + input$farm_number_cumulated + }, { + nfarm <- input$farm_number_cumulated + init_cumul_new <- init_cumul[1:nfarm,] updateMatrixInput(session, inputId = "fatalities_mat_cumulated", - value = matrix(init_cumul_new, nrow = nrow, ncol = 3, byrow = TRUE, - dimnames = list(number_parks, + value = matrix(init_cumul_new, nrow = nfarm, ncol = 3, byrow = FALSE, + dimnames = list(paste("Parc", c(1:nfarm)), c("Moyenne", "Erreur-type", - "Année de mise en service du parc")))) + "Année (début)")))) }) ##### @@ -652,7 +647,6 @@ server <- function(input, output, session){ shape = (mu/se)^2 scale = se^2/mu - ## Define x and y lim xx = yy = list() for(j in 1:nparc){ @@ -663,7 +657,6 @@ server <- function(input, output, session){ ylim = c(min(unlist(yy)), max(unlist(yy))*1.4) xlim = c(min(unlist(xx)), max(unlist(xx))) - ## Plot j=1 curve(dgamma(x, shape=shape[j], scale=scale[j]), @@ -734,11 +727,15 @@ server <- function(input, output, session){ # When analysis = cumulated impacts }else{ output$title_distri_plot <- renderText({ "Mortalités annuelles par parc (impacts cumulés)" }) - output$distri_plot <- renderPlot({ - plot_gamma_cumulated_impacts(mu = input$fatalities_mat_cumulated[,1], + # Plot: note we use the "NULL + delay" sequence only to avoid error message in R console + output$distri_plot <- NULL + delay(5, + output$distri_plot <- renderPlot({ + plot_gamma_cumulated_impacts(mu = input$fatalities_mat_cumulated[,1], se = input$fatalities_mat_cumulated[,2], nparc = input$farm_number_cumulated) - }) + }) + ) } # end "if" }, ignoreInit = FALSE) diff --git a/inst/ShinyApp/ui.R b/inst/ShinyApp/ui.R index e2f220023b4793476296ec01448f1f7c15c55d01..0ed29f66324752fde8cf76cdd14c85ba0fbe6b12 100644 --- a/inst/ShinyApp/ui.R +++ b/inst/ShinyApp/ui.R @@ -56,12 +56,20 @@ rm(list = ls(all.names = TRUE)) ## Other pre-fill data # fatalities for several wind farms (cumulated impacts) - init_cumul <- c(10, 5, 8, - 0.05, 0.05, 0.05, - 2010, 2015, 2018) - - init_cumul_add <- c(3, 0.05, 2020) + set.seed(seed = 200) + init_cumul <- + matrix( + round(c( + runif(n = 20, 1, 10), + runif(n = 20, 0.01, 0.20), + sort(sample(x = 2000:2050, size = 20, replace = TRUE)) + ), 2), + nrow = 20, ncol = 3, byrow = FALSE) + + # Undo last 'set.seed' + set.seed( ((((Sys.time() %>% as.numeric) %% 1e10) * 1e9) %% 1e5) %>% round ) } + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~###