-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'redesign' of https://github.com/JGCRI/hectorui into red…
…esign
- Loading branch information
Showing
6 changed files
with
150 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Run Hector given SSP input, start and end years for model run | ||
# Plot function | ||
|
||
# Default values set for SSP, start/end years, and selected var for plot | ||
|
||
graph_ui <- function(id) { | ||
ns <- NS(id) | ||
fluidRow( | ||
actionButton(ns("plot"),"Plot"), | ||
plotOutput(ns("graph")) | ||
) | ||
} | ||
|
||
graph_server <- function(id,r6) { | ||
moduleServer(id, function(input, output, session) { | ||
observe({ | ||
#filtered_output <- filter(r6$output,variable=="RF_tot") | ||
output$graph <- renderPlot({ | ||
ggplot(r6$output) + | ||
aes(x = year, y = value) + | ||
geom_line() + | ||
facet_wrap(~variable, scales = "free_y") | ||
}) | ||
}) %>% | ||
bindEvent(input$plot) | ||
}) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Run Hector using R6 module | ||
|
||
run_ui <- function(id) { | ||
ns <- NS(id) | ||
|
||
tagList( | ||
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", | ||
"SSP 2-4.5"="input/hector_ssp245.ini", | ||
"SSP 3-7.0"="input/hector_ssp370.ini", | ||
"SSP 4-3.4"="input/hector_ssp434.ini", | ||
"SSP 4-6.0"="input/hector_ssp460.ini", | ||
"SSP 5-3.4OS"="input/hector_ssp534-over.ini", | ||
"SSP 5-8.5"="input/hector_ssp585.ini"), | ||
selected = "input/hector_ssp119.ini"), | ||
sliderInput(ns("start"), label="Select start date:", | ||
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")) | ||
) | ||
} | ||
|
||
run_server <- function(id, r6) { | ||
moduleServer(id, function(input, output, session) { | ||
observe({ | ||
# store inputs in r6 class | ||
r6$ini_file <- reactive({system.file(input$ssp_path,package="hector")}) | ||
r6$start <- reactive({input$start}) | ||
r6$end <- reactive({input$end}) | ||
|
||
# run hector using inputs | ||
#output$done <- renderPrint({"Running..."}) # how to show this, then be replaced by "Done" ? | ||
print("Running...") # in command line | ||
core <- newcore(r6$ini_file()) | ||
run(core) | ||
r6$output <- fetchvars(core,r6$start():r6$end()) | ||
output$done <- renderPrint({"Done"}) | ||
print("Done") # in command line | ||
}) %>% | ||
bindEvent(input$run) # triggers when "Run Model" is clicked | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Run Hector given SSP input, start and end years for model run | ||
# Print function | ||
|
||
# Default values set for SSP, start/end years, and selected var for plot | ||
|
||
summary_ui <- function(id) { | ||
ns <- NS(id) | ||
fluidRow( | ||
actionButton(ns("print"),"Print"), | ||
tableOutput(ns("summary")) | ||
) | ||
} | ||
|
||
summary_server <- function(id,r6) { | ||
moduleServer(id, function(input, output, session) { | ||
observe({ | ||
output$summary <- renderTable({r6$output}) | ||
}) %>% | ||
bindEvent(input$print) # run when Print button is clicked | ||
|
||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
|
||
library(R6) | ||
library(shiny) | ||
library(hector) | ||
library(dplyr) | ||
library(ggplot2) | ||
library(shinycssloaders) | ||
|
||
source("./components/modules/mod_graph.r") | ||
source("./components/modules/mod_run.r") | ||
source("./components/modules/mod_summary.r") | ||
|
||
source("./components/modules/module_test.r") | ||
# Define R6 class | ||
HectorInputs <- R6Class( | ||
classname = "HectorInputs", | ||
public = list( | ||
ini_file = NULL, | ||
start = NA, | ||
end = NA, | ||
output = NULL, | ||
initialize = function(ini_file=system.file("input/hector_ssp245.ini", | ||
package="hector"), | ||
start=2000,end=2300) { | ||
self$ini_file <- ini_file | ||
self$start <- start | ||
self$end <- end | ||
stopifnot(end>start) #gotta have the start year before the end year | ||
} | ||
) | ||
) |