Commit 1d9b2d35 by Jan Wijffels

Add simple graph

parent b4bff142
...@@ -22,7 +22,7 @@ run_app('citizenair.Rmd') ...@@ -22,7 +22,7 @@ run_app('citizenair.Rmd')
install.packages(c('flexdashboard', 'shiny', 'shinyWidgets', 'rmarkdown', 'DT')) install.packages(c('flexdashboard', 'shiny', 'shinyWidgets', 'rmarkdown', 'DT'))
install.packages(c('data.table', 'httr', 'readxl', 'magrittr', 'cellranger', 'fasttime')) install.packages(c('data.table', 'httr', 'readxl', 'magrittr', 'cellranger', 'fasttime'))
install.packages(c('leaflet', 'sp', 'rgeos')) install.packages(c('leaflet', 'sp', 'rgeos'))
install.packages(c('dygraphs')) install.packages(c('dygraphs', 'xts'))
devtools::install_github('bnosac/BelgiumMaps.Statbel') devtools::install_github('bnosac/BelgiumMaps.Statbel')
devtools::install_github('52North/sensorweb4R') devtools::install_github('52North/sensorweb4R')
devtools::install_git('https://www.datatailor.be/vmm/citizenair', subdir = 'citizenair') devtools::install_git('https://www.datatailor.be/vmm/citizenair', subdir = 'citizenair')
......
...@@ -6,7 +6,7 @@ RUN R -e "install.packages(c('devtools'), repos='https://cloud.r-project.org/')" ...@@ -6,7 +6,7 @@ RUN R -e "install.packages(c('devtools'), repos='https://cloud.r-project.org/')"
RUN R -e "install.packages(c('flexdashboard', 'shiny', 'shinyWidgets', 'rmarkdown', 'DT'), repos='https://cloud.r-project.org/')" RUN R -e "install.packages(c('flexdashboard', 'shiny', 'shinyWidgets', 'rmarkdown', 'DT'), repos='https://cloud.r-project.org/')"
RUN R -e "install.packages(c('data.table', 'httr', 'readxl', 'magrittr', 'cellranger', 'fasttime'), repos='https://cloud.r-project.org/')" RUN R -e "install.packages(c('data.table', 'httr', 'readxl', 'magrittr', 'cellranger', 'fasttime'), repos='https://cloud.r-project.org/')"
RUN R -e "install.packages(c('leaflet', 'sp', 'rgeos'), repos='https://cloud.r-project.org/')" RUN R -e "install.packages(c('leaflet', 'sp', 'rgeos'), repos='https://cloud.r-project.org/')"
RUN R -e "install.packages(c('dygraphs'), repos='https://cloud.r-project.org/')" RUN R -e "install.packages(c('dygraphs', 'xts'), repos='https://cloud.r-project.org/')"
RUN R -e "devtools::install_github('bnosac/BelgiumMaps.Statbel')" RUN R -e "devtools::install_github('bnosac/BelgiumMaps.Statbel')"
RUN R -e "devtools::install_github('52North/sensorweb4R')" RUN R -e "devtools::install_github('52North/sensorweb4R')"
RUN git -c http.sslVerify=false clone https://www.datatailor.be/vmm/citizenair RUN git -c http.sslVerify=false clone https://www.datatailor.be/vmm/citizenair
......
...@@ -39,14 +39,19 @@ citizenair_userdata_empty <- function(){ ...@@ -39,14 +39,19 @@ citizenair_userdata_empty <- function(){
#' ca #' ca
#' ca$getPhenomena() #' ca$getPhenomena()
#' #'
#' ## get stations
#' library(sp) #' library(sp)
#' x <- ca$getStations() #' x <- ca$getStations()
#' plot(x) #' plot(x)
#' #'
#' ## get official measurements
#' library(lubridate) #' library(lubridate)
#' x <- ca$fetch_timeseries(id = "1030") #' x <- ca$fetch_timeseries(id = "1030")
#' period <- as.interval(as.POSIXct(Sys.Date() - 14), Sys.time()) #' period <- as.interval(as.POSIXct(Sys.Date() - 14), Sys.time())
#' x <- ca$fetch_timeseries(id = "1030", time_span = period) #' x <- ca$fetch_timeseries(id = "1030", time_span = period)
#' ## set citizen measurements
#' filename <- system.file(package = "citizenair", "data-raw", "citizenair-example.xls")
#' ca$setCitizenData(filename)
CitizenAir <- R6::R6Class("CitizenAir", CitizenAir <- R6::R6Class("CitizenAir",
public = list( public = list(
endpoint = NULL, endpoint = NULL,
...@@ -104,6 +109,9 @@ CitizenAir <- R6::R6Class("CitizenAir", ...@@ -104,6 +109,9 @@ CitizenAir <- R6::R6Class("CitizenAir",
}, },
getPhenomena = function(){ getPhenomena = function(){
self$stations$phenomena$id self$stations$phenomena$id
},
setCitizenData = function(file, name=basename(file)){
self$data <- read_citizenair(file)
} }
), ),
private = list() private = list()
......
...@@ -23,13 +23,15 @@ library(rgeos) ...@@ -23,13 +23,15 @@ library(rgeos)
library(citizenair) library(citizenair)
library(DT) library(DT)
library(sp) library(sp)
library(xts)
library(dygraphs)
data("BE_ADMIN_REGION", package = "BelgiumMaps.StatBel") data("BE_ADMIN_REGION", package = "BelgiumMaps.StatBel")
dashinput <- list() dashinput <- list()
dashinput$endpoint <- as.Endpoint("http://geo.irceline.be/sos/api/v1") dashinput$endpoint <- as.Endpoint("http://geo.irceline.be/sos/api/v1")
dashinput$ca <- CitizenAir$new(endpoint = dashinput$endpoint) dashinput$appdata <- CitizenAir$new(endpoint = dashinput$endpoint)
dashinput$region <- subset(BE_ADMIN_REGION, TX_RGN_DESCR_NL %in% "Vlaams Gewest") dashinput$region <- subset(BE_ADMIN_REGION, TX_RGN_DESCR_NL %in% "Vlaams Gewest")
dashinput$stations_sp <- dashinput$ca$getStations() dashinput$stations_sp <- dashinput$appdata$getStations()
dashinput$stations_sp <- dashinput$stations_sp[sapply(1:nrow(dashinput$stations_sp), dashinput$stations_sp <- dashinput$stations_sp[sapply(1:nrow(dashinput$stations_sp),
FUN=function(idx) gIntersects(dashinput$region, dashinput$stations_sp[idx, ])), ] FUN=function(idx) gIntersects(dashinput$region, dashinput$stations_sp[idx, ])), ]
``` ```
......
...@@ -44,10 +44,11 @@ citizenair_userdata <- reactive({ ...@@ -44,10 +44,11 @@ citizenair_userdata <- reactive({
result$file <- default result$file <- default
}else{ }else{
showNotification("We lezen uw Excel bestand in wacht even...") showNotification("We lezen uw Excel bestand in wacht even...")
x <- try(read_citizenair(result$file)) x <- try(dashinput$appdata$setCitizenData(result$file))
if(inherits(x, "try-error")){ if(inherits(x, "try-error")){
showNotification(sprintf("Er loopt iets fout, is uw data bestand wel een correct bestand? %s", as.character(attributes(x)$condition))) showNotification(sprintf("Er loopt iets fout, is uw data bestand wel een correct bestand? %s", as.character(attributes(x)$condition)))
}else{ }else{
x <- dashinput$appdata$data
result$data$polluenten <- x$phenomena result$data$polluenten <- x$phenomena
result$data$meta <- as.data.frame(x, type = "meta") result$data$meta <- as.data.frame(x, type = "meta")
result$data$phenomena <- as.data.frame(x, type = "measurements") result$data$phenomena <- as.data.frame(x, type = "measurements")
......
...@@ -3,7 +3,16 @@ ...@@ -3,7 +3,16 @@
### Toon je metingen ### Toon je metingen
gemiddelde / mediaan / piek / dal ```{r}
x <- dashinput$appdata$fetch_timeseries("1030")
x <- setDT(x)
ts <- dcast.data.table(data = x, formula = time ~ phenomena_label, fun.aggregate = mean, value.var = "value")
ts <- setDF(ts)
g <- xts(ts[, -1], order.by=ts[,1])
g <- dygraph(g, main = "Tijdreeks van 1030 - Under construction")
g <- dyRangeSelector(g, height = 20)
g
```
### Vergelijk met officiële metingen ### Vergelijk met officiële metingen
......
...@@ -36,13 +36,18 @@ ca <- CitizenAir$new(e) ...@@ -36,13 +36,18 @@ ca <- CitizenAir$new(e)
ca ca
ca$getPhenomena() ca$getPhenomena()
## get stations
library(sp) library(sp)
x <- ca$getStations() x <- ca$getStations()
plot(x) plot(x)
## get official measurements
library(lubridate) library(lubridate)
x <- ca$fetch_timeseries(id = "1030") x <- ca$fetch_timeseries(id = "1030")
period <- as.interval(as.POSIXct(Sys.Date() - 14), Sys.time()) period <- as.interval(as.POSIXct(Sys.Date() - 14), Sys.time())
x <- ca$fetch_timeseries(id = "1030", time_span = period) x <- ca$fetch_timeseries(id = "1030", time_span = period)
## set citizen measurements
filename <- system.file(package = "citizenair", "data-raw", "citizenair-example.xls")
ca$setCitizenData(filename)
} }
\keyword{datasets} \keyword{datasets}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment