diff --git a/h2/components/modules/mod_graph.R b/h2/components/modules/mod_graph.R index d9fcc11..f4dd39d 100644 --- a/h2/components/modules/mod_graph.R +++ b/h2/components/modules/mod_graph.R @@ -5,31 +5,55 @@ 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())), - # 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"), + + 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? + "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()), + "Halocarbon Forcings" = list("CF4 Forcing"="RF_CF4", #function doesn't give the correct output? + "C2F6 Forcing"="RF_C2F6", + "HFC-23 Forcing"="RF_HFC23", + "HFC-4310 Forcing"="RF_HFC4310", + "HFC-125 Forcing"="RF_HFC125", + "HFC-143a Forcing"="RF_HFC143a", + "HFC-245fa Forcing"="RF_HFC245fa", + "SF6 Forcing"="RF_SF6", + "CFC-11 Forcing"="RF_CFC11", + "CFC-12 Forcing"="RF_CFC12", + "CFC-113 Forcing"="RF_CFC113", + "CFC-114 Forcing"="RF_CFC114", + "CFC-115 Forcing"="RF_CFC115", + "CCl4 Forcing"="RF_CCl4", + "CH3CCl3 Forcing"="RF_CH3CCl3", + "Halon-1211 Forcing"="RF_halon1211", + "Halon-1301 Forcing"="RF_halon1301", + "Halon-2402 Forcing"="RF_halon2402", + "CH3Cl Forcing"="RF_CH3Cl", + "CH3Br Forcing"="RF_CH3Br"), + "Methane" = list("Atmospheric CH4" = CONCENTRATIONS_CH4(), + "CH4 Emissions" = EMISSIONS_CH4()), + "SO2" = list("Anthropogenic SO2"=EMISSIONS_SO2(), + "Volcanic SO2"=VOLCANIC_SO2()), + "Temperature" = list("Global Mean Temp" = GLOBAL_TAS(), + "Equilibrium Global Temp" = GMST(), # i think? + "Ocean Surface Temp" = SST(), + "Ocean Air Temp" = OCEAN_TAS(), + "Heat Flux - Mixed Layer Ocean" = FLUX_MIXED(), + "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"), @@ -43,6 +67,13 @@ graph_server <- function(id, r6) { observe({ if (r6$save == TRUE) { + + # Get labels given input + key <- reactive({input$variable}) + title <- title[[key()]] + ylabel <- units[[key()]] + + # Filter data for selected variable filtered_output <- filter(r6$output[[r6$run_name()]], variable == r6$selected_var()) @@ -61,18 +92,24 @@ graph_server <- function(id, r6) { ) %>% layout( xaxis = list(title = "Year"), - yaxis = list(title = "Global Temperature (C)"), - title = "Global Temperature at Surface" + yaxis = list(title = ylabel), + title = title ) }) } + if (r6$save == FALSE) { - browser() - # r6$selected_var <- reactive({input$variable}) - # - # filtered_output <- - # filter(r6$output, variable == r6$selected_var()) - #browser() + r6$selected_var <- reactive({input$variable}) + + # Get labels given input + key <- reactive({input$variable}) + title <- title[[key()]] + ylabel <- units[[key()]] + + # Filter data for selected variable + filtered_output <- + filter(r6$no_save, variable == r6$selected_var()) + output$graph <- renderPlotly({ plot_ly( r6$output, @@ -88,8 +125,8 @@ graph_server <- function(id, r6) { ) %>% layout( xaxis = list(title = "Year"), - #yaxis = list(title = r6$selected_var()), - title = input$variable + yaxis = list(title = ylabel), + title = title ) }) } @@ -97,3 +134,5 @@ graph_server <- function(id, r6) { bindEvent(input$run, ignoreNULL = TRUE, ignoreInit = TRUE) }) } + +# add reset variables button diff --git a/h2/global.r b/h2/global.r index adfb4c3..4b70015 100644 --- a/h2/global.r +++ b/h2/global.r @@ -46,3 +46,101 @@ HectorInputs <- R6Class( } ) ) + +title <- list("CO2_concentration" = "Atmospheric CO2", + "atmos_co2" = "Atmospheric Carbon Pool", + "ffi_emissions" = "FFI Emissions", + "luc_emissions" = "LUC Emissions", + "N2O_concentration" = "N2O Concentration", + "BC_emissions" = "Black Carbon Emissions", + "OC_emissions" = "Organic Carbon Emissions", + "RF_tot" = "RF - Total", + "RF_albedo" = "RF - Albedo", + "RF_CO2" = "RF - CO2", + "RF_N2O" = "RF - N2O", + "RF_BC" = "RF - Black Carbon", + "RF_OC" = "RF - Organic Carbon", + "RF_SO2" = "RF - Total SO2", + "RF_VOL" = "RF - Volcanic Activity", + "RF_CH4" = "RF - CH4", + "RF_CF4" = "CF4 Forcing", + "RF_C2F6" = "C2F6 Forcing", + "RF_HFC23" = "HFC-23 Forcing", + "RF_HFC4310" = "HFC-4310 Forcing", + "RF_HFC125" = "HFC-125 Forcing", + "RF_HFC143a" = "HFC-143a Forcing", + "RF_HFC245fa" = "HFC-245fa Forcing", + "RF_SF6" = "SF6 Forcing", + "RF_CFC11" = "CFC-11 Forcing", + "RF_CFC12" = "CFC-12 Forcing", + "RF_CFC113" = "CFC-113 Forcing", + "RF_CFC114" = "CFC-114 Forcing", + "RF_CFC115" = "CFC-115 Forcing", + "RF_CCl4" = "CCl4 Forcing", + "RF_CH3CCl3" = "CH3CCl3 Forcing", + "RF_halon1211" = "Halon-1211 Forcing", + "RF_halon1301" = "Halon-1301 Forcing", + "RF_halon2402" = "Halon-2402 Forcing", + "RF_CH3Cl" = "CH3Cl Forcing", + "RF_CH3Br" = "CH3Br Forcing", + "CH4_concentration" = "Atmospheric CH4", + "CH4_emissions" = "CH4 Emissions", + "SO2_emissions" = "Anthropogenic SO2", + "SV" = "Volcanic SO2", + "global_tas" = "Global Mean Temperature", + "gmst" = "Equilibrium Global Temperature", + "sst" = "Ocean Surface Temperature", + "ocean_tas" = "Ocean Air Temperature", + "heatflux_mixed" = "Heat Flux - Mixed Layer Ocean", + "heatflux_interior" = "Heat Flux - Interior Layer Ocean", + "heatflux" = "Total Heat Flux - Ocean" +) + +units <- list("CO2_concentration" = "DegC", + "atmos_co2" = "Pg C", + "ffi_emissions" = "Pg C/yr", + "luc_emissions" = "Pg C/yr", + "N2O_concentration" = "ppbv N2O", + "BC_emissions" = "Tg", + "OC_emissions" = "Tg", + "RF_tot" = "RF - Total", + "RF_albedo" = "W/m2", + "RF_CO2" = "W/m2", + "RF_N2O" = "W/m2", + "RF_BC" = "W/m2", + "RF_OC" = "W/m2", + "RF_SO2" = "W/m2", + "RF_VOL" = "W/m2", + "RF_CH4" = "W/m2", + "RF_CF4" = "W/m2", + "RF_C2F6" = "W/m2", + "RF_HFC23" = "W/m2", + "RF_HFC4310" = "W/m2", + "RF_HFC125" = "W/m2", + "RF_HFC143a" = "W/m2", + "RF_HFC245fa" = "W/m2", + "RF_SF6" = "W/m2", + "RF_CFC11" = "W/m2", + "RF_CFC12" = "W/m2", + "RF_CFC113" = "W/m2", + "RF_CFC114" = "W/m2", + "RF_CFC115" = "W/m2", + "RF_CCl4" = "W/m2", + "RF_CH3CCl3" = "W/m2", + "RF_halon1211" = "W/m2", + "RF_halon1301" = "W/m2", + "RF_halon2402" = "W/m2", + "RF_CH3Cl" = "W/m2", + "RF_CH3Br" = "W/m2", + "CH4_concentration" = "ppbv CH4", + "CH4_emissions" = "Tg CH4", + "SO2_emissions" = "Gg SO2", + "SV" = "W/m2", + "global_tas" = "DegC", + "gmst" = "DegC", + "sst" = "DegC", + "ocean_tas" = "DegC", + "heatflux_mixed" = "W/m2", + "heatflux_interior" = "W/m2", + "heatflux" = "W/m2" +)