Skip to content

Commit

Permalink
Try save toggle without modal
Browse files Browse the repository at this point in the history
  • Loading branch information
stephpenn1 committed Dec 6, 2023
1 parent 51b3b88 commit 95a36a5
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 174 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)
31 changes: 31 additions & 0 deletions h2/components/functions/func_graph_plots.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@


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",last(r6$output)$variable[1])) +
theme(legend.position = "bottom")} %>%
plotly::ggplotly()

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

{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", 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;
}
}
75 changes: 41 additions & 34 deletions h2/components/modules/mod_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,47 @@

graph_ui <- function(id) {
ns <- NS(id)
fluidRow(selectInput(ns("variable"), "Select a variable to plot:",
list("Carbon Cycle" = list("Atmospheric CO2" = CONCENTRATIONS_CO2(),
"FFI Emissions" = FFI_EMISSIONS(),
"LUC Emissions" = LUC_EMISSIONS()),
"Concentrations" = list("N2O Concentration" = CONCENTRATIONS_N2O()),
"Emissions" = list("Black Carbon Emissions" = EMISSIONS_BC(),
"Organic Carbon Emissions" = EMISSIONS_OC()),
"Forcings" = list("RF - Total" = RF_TOTAL(),
"RF - Albedo" = RF_ALBEDO(),
"RF - CO2" = RF_CO2(),
"RF - N2O" = RF_N2O(),
"RF - Black Carbon" = RF_BC(),
"RF - Organic Carbon" = RF_OC(),
"RF - Total SO2" = RF_SO2(),
"RF - Volcanic Activity" = RF_VOL(),
"RF - CH4" = RF_CH4()))),
# selectInput(ns("variable"), "Select a variable to plot:",
# c("Global Mean Temperature" = "global_tas",
# "Atmospheric CO2" = "CO2_concentration",
# "RF - Total" = "RF_tot",
# "RF - CO2" = "RF_CO2",
# "Atmospheric N2O" = CONCENTRATIONS_N2O()),
# selected = "global_tas"),
# fluidRow(
# selectInput(ns("variable"), "Select a variable to plot:",
# list("Carbon Cycle" = list("Atmospheric CO2" = CONCENTRATIONS_CO2(),
# "FFI Emissions" = FFI_EMISSIONS(),
# "LUC Emissions" = LUC_EMISSIONS()),
# "Concentrations" = list("N2O Concentration" = CONCENTRATIONS_N2O()),
# "Emissions" = list("Black Carbon Emissions" = EMISSIONS_BC(),
# "Organic Carbon Emissions" = EMISSIONS_OC()),
# "Forcings" = list("RF - Total" = RF_TOTAL(),
# "RF - Albedo" = RF_ALBEDO(),
# "RF - CO2" = RF_CO2(),
# "RF - N2O" = RF_N2O(),
# "RF - Black Carbon" = RF_BC(),
# "RF - Organic Carbon" = RF_OC(),
# "RF - Total SO2" = RF_SO2(),
# "RF - Volcanic Activity" = RF_VOL(),
# "RF - CH4" = RF_CH4())),
# selected = "Atmospheric CO2"),
# selectInput(ns("variable"), "Select a variable to plot:",
# c("Global Mean Temperature" = "global_tas",
# "Atmospheric CO2" = "CO2_concentration",
# "RF - Total" = "RF_tot",
# "RF - CO2" = "RF_CO2",
# "Atmospheric N2O" = CONCENTRATIONS_N2O()),
# selected = "global_tas"),
# 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) {
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 All @@ -61,14 +67,15 @@ graph_server <- function(id, r6) {
})
}
if (r6$save == FALSE) {
r6$selected_var <- reactive({input$variable})

filtered_output <-
filter(r6$no_save, variable == r6$selected_var())
browser()
# r6$selected_var <- reactive({input$variable})
#
# filtered_output <-
# filter(r6$output, variable == r6$selected_var())
#browser()
output$graph <- renderPlotly({
plot_ly(
filtered_output,
r6$output,
x = ~ year,
y = ~ value,
type = 'scatter',
Expand All @@ -81,12 +88,12 @@ graph_server <- function(id, r6) {
) %>%
layout(
xaxis = list(title = "Year"),
yaxis = list(title = r6$selected_var()),
#yaxis = list(title = r6$selected_var()),
title = input$variable
)
})
}
}) %>%
bindEvent(input$plot, ignoreNULL = TRUE, ignoreInit = FALSE)
bindEvent(input$run, ignoreNULL = TRUE, ignoreInit = TRUE)
})
}
}
Loading

0 comments on commit 95a36a5

Please sign in to comment.