Skip to content

Commit

Permalink
Add scenario name, select "save slot"
Browse files Browse the repository at this point in the history
Added text input to give runs names, and "save slots" for runs
  • Loading branch information
ciara-donegan committed Sep 26, 2023
1 parent d33d517 commit eaa89fb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 18 deletions.
3 changes: 1 addition & 2 deletions h2/app.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ui <- fluidPage(
tabPanel(title = "Guides",),
tabPanel(title = "Explore Hector",
fluidRow(
column(2,
column(3,
wellPanel(
run_ui("run_1"),
download_ui("download_1")
Expand All @@ -27,7 +27,6 @@ ui <- fluidPage(

server <- function(input, output, session) {
r6 <- HectorInputs$new() # r6 class
i <- reactiveVal(1) # set up pseudo loop

run_server("run_1", r6 = r6, i = i)
summary_server("summary_1", r6 = r6, i = i)
Expand Down
1 change: 0 additions & 1 deletion h2/components/modules/mod_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ download_server <- function(id, r6) {
content = function(file) {
write.csv(bind_rows(r6$output), file)
}

)
})
}
9 changes: 5 additions & 4 deletions h2/components/modules/mod_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ graph_server <- function(id, r6, i) {
moduleServer(id, function(input, output, session) {
observe({
filtered_output <-
filter(r6$output[[i() - 1]], variable == "CO2_concentration") #i increases at end of mod_run so output is i-1
#filter(bind_rows(r6$output), variable == "CO2_concentration")
filter(r6$output[[r6$i()]], variable == "global_tas")
#filter(bind_rows(r6$output), variable == "global_tas")
output$graph <- renderPlotly({
plot_ly(
filtered_output,
Expand All @@ -30,9 +30,10 @@ graph_server <- function(id, r6, i) {
) %>%
layout(
xaxis = list(title = "Year"),
yaxis = list(title = "CO2 Concentration (ppmv)"),
title = "CO2 Concentration"
yaxis = list(title = "Global Temperature (C)"),
title = "Global Temperature at Surface"
)
#ggplot(filtered_output, aes(x=year,y=value))
})
}) %>%
bindEvent(input$plot)
Expand Down
49 changes: 42 additions & 7 deletions h2/components/modules/mod_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ run_ui <- function(id) {
ns <- NS(id)

tagList(
textInput(ns("core_name"), "Input name for core:", placeholder="Unnamed Hector core"),
selectInput(ns("ssp_path"), label="Select SSP:",
choices = list("SSP 1-1.9"="input/hector_ssp119.ini",
"SSP 1-2.6"="input/hector_ssp126.ini",
Expand All @@ -18,8 +19,19 @@ run_ui <- function(id) {
min = 1750, max = 2300, value = 2000, sep=""),
sliderInput(ns("end"), "Select end date:",
min = 1750, max = 2300, value = 2300, sep=""),
actionButton(ns("run"),"Run Model"),
verbatimTextOutput(ns("done"))
radioButtons(ns("run_number"), label="Select run number:",
choices = list("1" = 1,
"2" = 2,
"3" = 3,
"4" = 4,
"5" = 5,
"6" = 6,
"7" = 7,
"8" = 8),
selected = "1", inline=TRUE),
actionButton(ns("run"),"Run Model")
#verbatimTextOutput(ns("done")),
#actionButton(ns("stop"),"show warning")
)
}

Expand All @@ -31,19 +43,42 @@ run_server <- function(id, r6, i) {
r6$ini_file <- reactive({system.file(input$ssp_path,package="hector")})
r6$start <- reactive({input$start})
r6$end <- reactive({input$end})
r6$i <- reactive({as.integer(input$run_number)})

# run hector using inputs
print("Running...") # in command line
core <- newcore(r6$ini_file())
run(core)
r6$output[[i()]] <- fetchvars(core,r6$start():r6$end()) %>% mutate(run=i())
output$done <- renderPrint({as.character(i()-1)}) #print run number
core <- reactive({newcore(r6$ini_file(),name=input$core_name)})
run(core())
r6$output[[r6$i()]] <- fetchvars(core(),r6$start():r6$end()) %>% mutate(run=r6$i())
output$done <- renderPrint({r6$i()}) #print run number
print("Done") # in command line

i(i() + 1) # add 1 to i. like a pseudo loop for storing output
#i(i() + 1) # add 1 to i. like a pseudo loop for storing output
print(r6$output)
#print(i())

if (length(r6$output) == 8 &&
identical(
lapply(r6$output, is.null),
list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
))
shinyalert(title = "Run Limit Reached",
text = "You have completed eight runs. Select a run to replace.",
type = "input",
inputType = "number")
}) %>%
bindEvent(input$run) # triggers when "Run Model" is clicked

# observe({
# shinyalert(title = "Run Limit Reached",
# text = "You have completed five runs. Select a run to replace.",
# type = "warning")
# }) %>%
# bindEvent(input$stop)

# showModal(modalDialog(
# title="Run Limit Reached",
# "You have reached the limit of 5 runs. Select a run to replace."
# )) # how to make it appear after 5 runs?
})
}
6 changes: 3 additions & 3 deletions h2/components/modules/mod_summary.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
summary_ui <- function(id) {
ns <- NS(id)
fluidRow(actionButton(ns("print"), "Print"),
dataTableOutput(ns("summary")))
DTOutput(ns("summary")))
}

summary_server <- function(id, r6, i) {
moduleServer(id, function(input, output, session) {
observe({
#browser()
hectoroutput <- r6$output[[i()-1]]
output$summary <- renderDataTable({hectoroutput})
hectoroutput <- r6$output[[r6$i()]]
output$summary <- renderDT({datatable(hectoroutput,editable=TRUE)})
}) %>%
bindEvent(input$print) # run when Print button is clicked

Expand Down
6 changes: 5 additions & 1 deletion h2/global.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ library(dplyr)
library(ggplot2)
library(shinycssloaders)
library(plotly)
library(shinyalert)
library(shinyalert) # don't need if we have shinyWidgets?
library(DT)
library(shinyWidgets)

source("./components/modules/mod_graph.r")
source("./components/modules/mod_run.r")
Expand All @@ -20,6 +22,7 @@ HectorInputs <- R6Class(
start = NA,
end = NA,
output = NULL,
i = NA,
initialize = function(ini_file = system.file("input/hector_ssp245.ini",
package = "hector"),
start = 2000,
Expand All @@ -28,6 +31,7 @@ HectorInputs <- R6Class(
self$start <- start
self$end <- end
self$output <- list()
self$i <- 1
stopifnot(end > start) #gotta have the start year before the end year
}
)
Expand Down

0 comments on commit eaa89fb

Please sign in to comment.