Skip to content

Instantly share code, notes, and snippets.

@autermann
Created April 22, 2015 10:32
Show Gist options
  • Save autermann/18f92933bc5c98060347 to your computer and use it in GitHub Desktop.
Save autermann/18f92933bc5c98060347 to your computer and use it in GitHub Desktop.
library(sensorweby)
library(shiny)
library(sensorweb4R)
# calling the shinyApp function creates a new Shiny application
runApp(shinyApp(
# create the client side of the application in the "ui" parameter
ui = shinyUI(
# the swcPage creates a new sensor web client layout
swcPage(
title = "Sensorweby Timeplot",
caption = c(en = "Timeplot", de = "Timeplot"),
swcIntervalInput("time"),
swcTimeseriesInput("series"),
swcFullPanel(
plotOutput("timePlot", width = "100%", height = "100%"))
)
),
# create the server side of the application in the "server" parameter
server = shinyServer(function(input, output, session) {
output$timePlot <- renderPlot({
# validate whether a time series has been selected in the client
validate(
need(length(input$series) > 0, 'No Timeseries selected'),
need(input$time, "No timespan selected")
)
# request the data
data <- getData(input$series, timespan = input$time)
# create a data.frame containing all series
times <- unique(sort(do.call(c, lapply(data, time))))
values <- lapply(data, function(x) value(x)[match(times, time(x))])
names(values) <- sensorweb4R::id(input$series)
values$date <- times
df <- as.data.frame(values)
# validate if data frame contains data
validate(need(dim(df)[1] > 0, "No data available"))
# plot it
openair::timePlot(df, name.pol = label(input$series), ylab = c(),
plot.type = "h", smooth = TRUE, ci = TRUE,
pollutant = names(df)[!(names(df) %in% "date")])
})
})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment