Skip to content

Commit

Permalink
Merge pull request #82 from JGCRI/bug-disconnect
Browse files Browse the repository at this point in the history
Fixed disconnect when output variable is chosen before "Load Graph"
  • Loading branch information
stephpenn1 authored Sep 18, 2024
2 parents 1d11114 + f1103f3 commit dca760f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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

0 comments on commit dca760f

Please sign in to comment.