diff --git a/h2/components/modules/mod_graph.R b/h2/components/modules/mod_graph.R index 235d0b7..0362f3e 100644 --- a/h2/components/modules/mod_graph.R +++ b/h2/components/modules/mod_graph.R @@ -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, diff --git a/h2/components/modules/mod_run.R b/h2/components/modules/mod_run.R index 60a2e7c..ade1217 100644 --- a/h2/components/modules/mod_run.R +++ b/h2/components/modules/mod_run.R @@ -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 diff --git a/h2/components/modules/mod_summary.r b/h2/components/modules/mod_summary.r index eb7c35a..698a823 100644 --- a/h2/components/modules/mod_summary.r +++ b/h2/components/modules/mod_summary.r @@ -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 diff --git a/h2/global.r b/h2/global.r index 48d0968..85500c4 100644 --- a/h2/global.r +++ b/h2/global.r @@ -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")