diff --git a/inst/shinyApp/components/modules/mod_run.R b/inst/shinyApp/components/modules/mod_run.R index da6cb83..c7079d3 100644 --- a/inst/shinyApp/components/modules/mod_run.R +++ b/inst/shinyApp/components/modules/mod_run.R @@ -10,7 +10,7 @@ run_ui <- function(id) { label = "Select SSPs:", choices = scenarios, multiple = TRUE, - selected = "input/hector_ssp245.ini"), + selected = list("input/hector_ssp245.ini")), sliderInput(ns("time"), label="Select dates:", min = 1750, max = 2300, value = c(1900,2100), sep="", width = "90%", step=5), h5("Include permafrost thaw:", id = "perm-lab"), @@ -99,12 +99,12 @@ run_server <- function(id, r6) { r6$selected_var <- reactive({input$variable}) r6$run_name <- reactive({input$run_name}) - r6$ini_file <- reactive({system.file(input$ssp_path[i],package="hector")}) + r6$ini_file <- system.file(input$ssp_path[i],package="hector") r6$time <- reactive({input$time}) - withProgress(message = paste("Running Hector", names(which(scenarios == input$ssp_path[i], arr.ind = FALSE)), "...\n"), value = 1/2, { + withProgress(message = paste("Running Hector", names(which(scenarios == r6$ini_file, arr.ind = FALSE)), "...\n"), value = 1/2, { print("Running...") # in command line - core <- reactive({newcore(r6$ini_file())}) # create core + core <- reactive({newcore(r6$ini_file)}) # create core # Set parameters using inputs (function to only call setvar once in final version) if (input$permafrost == TRUE) { @@ -140,6 +140,9 @@ run_server <- function(id, r6) { r6$output <- bind_rows(runs) print("Done") + + # Save scenarios used in run + r6$ini_list <- unique(r6$output$Scenario) output$graph <- renderPlotly({ graph_plots(r6 = r6) @@ -152,9 +155,9 @@ run_server <- function(id, r6) { r6$selected_var <- reactive({input$variable}) runs <- list() - for(i in 1:length(input$ssp_path)) { + for(i in 1:length(r6$ini_list)) { runs[[i]] <- fetchvars(r6$core[[i]], r6$time()[1]:r6$time()[2], vars = list(r6$selected_var())) %>% - mutate(Scenario = names(which(scenarios == input$ssp_path[i], arr.ind = FALSE))) + mutate(Scenario = r6$ini_list[i]) } r6$output <- bind_rows(runs) diff --git a/inst/shinyApp/global.r b/inst/shinyApp/global.r index 04a2d20..adc1d9e 100644 --- a/inst/shinyApp/global.r +++ b/inst/shinyApp/global.r @@ -37,6 +37,7 @@ HectorInputs <- R6Class( inputs = NULL, core = NULL, selected_var = NULL, + ini_list = NULL, initialize = function(ini_file = system.file("input/hector_ssp245.ini", package = "hector")) { self$ini_file <- ini_file @@ -45,6 +46,7 @@ HectorInputs <- R6Class( self$run_name <- 1 self$inputs <- list() self$selected_var <- "CO2_concentration" + self$ini_list <- list() } ) )