Skip to content

Commit

Permalink
formatting changes
Browse files Browse the repository at this point in the history
mainly just changed some formatting since last commit
  • Loading branch information
ciara-donegan committed Sep 18, 2023
1 parent a2b4dca commit d33d517
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 54 deletions.
1 change: 1 addition & 0 deletions h2/components/modules/mod_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ graph_server <- function(id, r6, i) {
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")
output$graph <- renderPlotly({
plot_ly(
filtered_output,
Expand Down
69 changes: 21 additions & 48 deletions h2/components/modules/mod_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,40 @@ 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"),
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, i) {
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
})
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
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
r6$output[[i()]] <- fetchvars(core,r6$start():r6$end()) %>% mutate(run=i())
output$done <- renderPrint({as.character(i()-1)}) #print run number
print("Done") # in command line

i(i() + 1) # add 1 to i. like a pseudo loop for storing output
Expand Down
10 changes: 4 additions & 6 deletions h2/components/modules/mod_summary.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
summary_ui <- function(id) {
ns <- NS(id)
fluidRow(actionButton(ns("print"), "Print"),
tableOutput(ns("summary")))
dataTableOutput(ns("summary")))
}

summary_server <- function(id, r6, i) {
moduleServer(id, function(input, output, session) {
observe({
hectoroutput <-
r6$output[[i() - 1]] #i increases at end of mod_run so output is i-1
output$summary <- renderTable({
hectoroutput
})
#browser()
hectoroutput <- r6$output[[i()-1]]
output$summary <- renderDataTable({hectoroutput})
}) %>%
bindEvent(input$print) # run when Print button is clicked

Expand Down
1 change: 1 addition & 0 deletions h2/global.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ library(dplyr)
library(ggplot2)
library(shinycssloaders)
library(plotly)
library(shinyalert)

source("./components/modules/mod_graph.r")
source("./components/modules/mod_run.r")
Expand Down

0 comments on commit d33d517

Please sign in to comment.