Created
April 22, 2015 10:32
-
-
Save autermann/ce895d2510124b783b17 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) | |
library(openair) | |
# 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 Scatterplot", | |
caption = c(en = "Scatterplot", | |
de = "Scatterplot"), | |
swcIntervalInput("time"), | |
swcTimeseriesInput("series"), | |
swcLeftPanel(plotOutput("scatterPlot", width="100%", height="100%")), | |
swcRightPanel(header = "Parameters", | |
# select between different plotting options: | |
selectInput( | |
'methodScatterPlot', 'scatterplot method', | |
choices = c( | |
"conventional scatter plot" = "scatter", | |
"hexbin" = "hexbin", | |
# optional: needs an x, y and z timeseries. | |
# See "z = sensorweb4R::id(input$series)[3]," below | |
# "binned or smooth surface plot" = "level", | |
"2D kernel density estimates" = "density" | |
), selectize = TRUE | |
), | |
selectInput( | |
'typeScatterPlot', 'scatterplot type', | |
choices = c( | |
"no time‐based differentiation" = "default", | |
"weekdays versus weekend" = "weekend", | |
"per day of the week" = "weekday", | |
"per season" = "season", | |
"per month" = "month", | |
"per year" = "year", | |
"per hour" = "hour" | |
), selectize = TRUE | |
), | |
selectInput( | |
'colorScatterPlot', 'colours used', | |
choices = c( | |
"jet" = "jet", | |
"increment" = "increment", | |
"heat" = "heat", | |
"default" = "default" | |
), selectize = TRUE | |
), | |
checkboxInput( | |
'linearScatterPlot', 'trendline', value = TRUE | |
) | |
) | |
) | |
), | |
# create the server side of the application in the "server" parameter | |
server = shinyServer(function(input, output, session) { | |
output$timeseriesSelection <- renderUI({ | |
validate(need(length(input$series) > 0, "No timeseries selected."), | |
need(length(input$series) > 1, "Not enough timeseries selected.")) | |
choices <- resourceURL(input$series) | |
names(choices) <- label(input$series) | |
selectInput("selectedTimeseries", | |
label = "Timeseries", | |
choices = choices) | |
}) | |
output$scatterPlot<- renderPlot({ | |
validate( | |
need(length(input$series) > 0, 'No Timeseries selected'), | |
need(input$time, "No timespan selected") | |
) | |
data <- getData(input$series, timespan = input$time) | |
times <- unique(sort(do.call(c, lapply(data, time)))) | |
values <- lapply(data, function(x) value(x)[match(times, time(x))]) | |
names(values) <- label(input$series) | |
values$date <- times | |
df <- as.data.frame(values) | |
validate(need(dim(df)[1] > 0, "No data available")) | |
scatterPlot(df, | |
x = names(df)[1], | |
y = names(df)[2], | |
# optional: for methodScatterPlot = level or scatter | |
# z = names(df)[3], | |
xlab = label(input$series)[1], | |
ylab = label(input$series)[2], | |
# getting interaction from “selectInput” and “checkboxInput” in the shinyUI: | |
method = input$methodScatterPlot, | |
col = input$colorScatterPlot, | |
type = input$typeScatterPlot, | |
linear = input$linearScatterPlot | |
) | |
}) | |
}) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment