# Fist try at R shiny script
library(shiny)
library(gassyPants)
ui <- fluidPage(
titlePanel("Coupled O2 and CO2 diel metabolism 'toy' model"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs and outputs----
sidebarPanel(
# Input: Sliders
sliderInput(inputId = "alphaPI",
label = "Slope of P-I curve (alpha PI; umol/m2/hr/uE)",
min = 0.1, max = 10, value = 1),
sliderInput(inputId = "Rstd",
label = "Ecosystem respiration to a standard temperature (Rstd; mol/m2/day)",
min = 0.1, max = 10, value = 1),
sliderInput(inputId = "kstd",
label = "Gas transfer velocity for CO2 at a standard temperature (kstd; m/hr)",
min = 0.01, max = 10, value = 0.15),
numericInput(inputId = "depth",
label = "Average stream depth (m)",
min = 0, max = 100, value = 0.5),
numericInput(inputId = "TAlk",
label = "Total alkalinity (umol/L)",
min = 0, max = 10000, value = 1000),
numericInput(inputId = "TCO2_init",
label = "Inital dissolved inorganic carbon (DIC; umol/L)",
min = 0, max = 10000, value = 1200),
numericInput(inputId = "pCO2_init",
label = "Inital partial pressure of dissolved CO2 (pCO2; uatm)",
min = 0, max = 10000, value = 2000),
h3(HTML("24 hr GPP: "),textOutput(outputId = "GPP")),
h3(HTML("24 hr ER: "),textOutput(outputId = "ER")),
h3(HTML("24 hr G: "),textOutput(outputId = "G"))
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Time series plot of dissolved O2 and pCO2 ----
plotOutput(outputId = "timeSeriesPlot_O2_CO2"),
plotOutput(outputId = "timeSeriesPlot_pH_DIC")
)
)
)
# Define server logic required to time seroes plot of model output ----
server <- function(input, output) {
# Background physical data from Fishtrap Cr.
# Not editable by users
x.lt <- as.POSIXlt(FishtrapCr$dateTime)
temperature <- FishtrapCr$Temp_C
PAR <- FishtrapCr$PAR_uE
localHour <- x.lt$hour + x.lt$min/60 + x.lt$sec/3600
DOY <- x.lt$yday
lat <- 48.93861111
long <- -122.47861111
tz <- -8
masl <- 1
salinity <- 0
# Static variable inputs (single value) from user interface
depth <- input$depth
TAlk <- input$TAlk
TCO2_init <- input$TCO2_init # Units of umol/L
pCO2_init <- input$pCO2_init # Units of uatm
# Dynamic variable inputs (sliders) from user interface
alphaPI_hr <- input$alphaPI # Units are umol/m2/hr/uE
Rstd_day <- input$Rstd # Units are mol/m2/day
kstd_hr <- input$kstd # Units are m/hr
modelResults <- main(temperature = temperature, localHour = localHour, DOY = DOY,
PAR = PAR, TALk = TAlk, TCO2_init = TCO2_init, pCO2_init = pCO2_init,
PCO2_air = 410, alphaPI_hr = alphaPI_hr, Rstd_day = Rstd_day,
kstd_hr = kstd_hr, referenceT = 20, lat = lat, long = long,
depth = depth, salinity = 0, masl=1)
# 2. Output is two plots and numberic values for 24 hr GPP, ER, and G
output$timeSeriesPlot_O2_CO2 <- renderPlot({
plotO2_CO2()
})
output$timeSeriesPlot_pH_DIC <- renderPlot({
plotpH_DIC()
})
#Add numeric outputs
output$GPP <- renderText(modelResults$GPP)
output$ER <- renderText(modelResults$ER)
output$G <- renderText(modelResults$G)
}
shinyApp(ui = ui, server = server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.