Skip to content

Commit

Permalink
Merge pull request #64 from JGCRI/sp-savetoggle
Browse files Browse the repository at this point in the history
Fix save toggle
  • Loading branch information
stephpenn1 authored Dec 18, 2023
2 parents bc7f3f7 + d83ee88 commit b89ca78
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 264 deletions.
20 changes: 7 additions & 13 deletions h2/app.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,25 @@ ui <- fluidPage(
collapsible = TRUE,
tabPanel(title = "Home",
includeHTML("./components/layout/homepage.html")),
tabPanel(title = "Guides",),
tabPanel(title = "Guides"),
tabPanel(title = "Explore Hector",
fluidRow(
column(3,
wellPanel(
run_ui("run_1"),
download_ui("download_1")
)),
column(4,
summary_ui("summary_1")),
column(4,
graph_ui("graph_1"))
)),
run_ui("run_1"),
#download_ui("download_1"),
)
),
tabPanel(title = "About")
),
)

server <- function(input, output, session) {
r6 <- HectorInputs$new() # r6 class

run_server("run_1", r6 = r6)
summary_server("summary_1", r6 = r6)
graph_server("graph_1", r6 = r6)
download_server("download_1", r6 = r6)
}

# Run the application
shinyApp(ui = ui, server = server)
shinyApp(ui = ui, server = server)
30 changes: 30 additions & 0 deletions h2/components/functions/func_graph_plots.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


graph_plots <- function(r6) {

if (r6$save == TRUE) {
#browser()

{ggplot(r6$no_save_output) +
geom_line(aes(x = year, y = value, color = ssp)) +
labs(x = "Year", y = last(r6$output)$variable[1],
title = paste0("Run Name: ", last(r6$output)$run[1], "\n", "Variable: ", last(r6$output)$variable[1])) +
theme(legend.position = "bottom")} %>%
plotly::ggplotly()

} else if(r6$save == FALSE) {

{ggplot(r6$no_save_output) +
geom_line(aes(x = year, y = value, color = ssp)) +
labs(x = "Year", y = r6$no_save_output$variable[1],
title = paste0("Run Name: Unsaved Run\n", "Variable: ", r6$no_save_output$variable[1]))} %>%
plotly::ggplotly() %>%
layout(
legend = list(
orientation = 'h', x = 0
)
)

}
}

4 changes: 1 addition & 3 deletions h2/components/layout/style copy.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

.test {
font-family:"Barlow Regular", Sans-Serif !important;
font-size: 20px;
}

h5 {
font-size: 20px;
font-weight: bold;
}
}
17 changes: 11 additions & 6 deletions h2/components/modules/mod_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

graph_ui <- function(id) {
ns <- NS(id)

fluidRow(selectInput(ns("variable"), "Select a variable to plot:",
list("Carbon Cycle" = list("Atmospheric CO2" = CONCENTRATIONS_CO2(),
"Atmospheric Carbon Pool" = ATMOSPHERIC_CO2(), # i think this is the right var?
Expand Down Expand Up @@ -54,13 +55,17 @@ graph_ui <- function(id) {
"Heat Flux - Interior Layer Ocean" = FLUX_INTERIOR(),
"Total Heat Flux - Ocean" = HEAT_FLUX()))),
# other variables can be found from the fetchvars help page
column(3,
actionButton(ns("plot"), "Plot"),
plotlyOutput(ns("graph")))
plotlyOutput(ns("graph"))
)
#)
}

graph_server <- function(id, r6) {
moduleServer(id, function(input, output, session) {
observe({

if (r6$save == TRUE) {

# Get labels given input
Expand All @@ -70,8 +75,8 @@ graph_server <- function(id, r6) {

# Filter data for selected variable
filtered_output <-
filter(r6$output[[r6$i()]], variable == input$variable)
filter(r6$output[[r6$run_name()]], variable == r6$selected_var())

output$graph <- renderPlotly({
plot_ly(
filtered_output,
Expand Down Expand Up @@ -107,7 +112,7 @@ graph_server <- function(id, r6) {

output$graph <- renderPlotly({
plot_ly(
filtered_output,
r6$output,
x = ~ year,
y = ~ value,
type = 'scatter',
Expand All @@ -126,8 +131,8 @@ graph_server <- function(id, r6) {
})
}
}) %>%
bindEvent(input$plot, ignoreNULL = TRUE, ignoreInit = FALSE)
bindEvent(input$run, ignoreNULL = TRUE, ignoreInit = TRUE)
})
}

# add reset variables button
# add reset variables button
Loading

0 comments on commit b89ca78

Please sign in to comment.