Created
April 22, 2015 10:32
-
-
Save autermann/18f92933bc5c98060347 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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