Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed disconnect when output variable is chosen before "Load Graph" #82

Merged
merged 7 commits into from
Sep 18, 2024
15 changes: 9 additions & 6 deletions inst/shinyApp/components/modules/mod_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions inst/shinyApp/global.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +46,7 @@ HectorInputs <- R6Class(
self$run_name <- 1
self$inputs <- list()
self$selected_var <- "CO2_concentration"
self$ini_list <- list()
}
)
)
Expand Down
Loading