Commit ab43a150 by Jan Wijffels

Init

parents
# citizenair
##### *Citizen Air: meet - evalueer - vergelijk*
> Deze toepassing laat je toe om de kwaliteit van je eigen luchtmeting in te schatten. Hiervoor moet je je data plaatsen in het template dat je via www.hoemeetiklucht.eu kan samenstellen.
## Documentatie
Aan het werk
![](http://www.textfiles.com/underconstruction/HeHeartlandPark2601underconstructionbar9.gif)
### Installatie
```r
## Install packages
install.packages(c("flexdashboard", "shiny", "shinyWidgets", "rmarkdown"))
install.packages(c("data.table", "httr", "readxl", "magrittr"))
install.packages(c("leaflet", "sp", "rgeos", "magrittr"))
devtools::install_github("bnosac/BelgiumMaps.Statbel")
devtools::install_github("52North/sensorweb4R")
## Run the app
rmarkdown::run("apps/citizenair.Rmd")
```
## Over
Deze applicatie werd ontwikkeld door
- De Vlaamse Milieu Maatschappij
- IRCELINE
- www.bnosac.be
![](img/logo-vlaanderen-is-milieu.png)
---
title: "Citizen Air"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
logo: img/logo-irceline-small.png
theme: lumen
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(shinyWidgets)
library(data.table)
library(sensorweb4R)
library(httr)
library(readxl)
library(sp)
library(leaflet)
library(magrittr)
library(BelgiumMaps.StatBel)
library(rgeos)
data("BE_ADMIN_REGION")
settings <- list()
read_citizenair <- function(file = file.path(getwd(), "apps/data/test.xls")){
fname <- file
sheets <- readxl::excel_sheets(fname)
read_one_meta <- function(file, sheet){
x <- readxl::read_excel(path = file, sheet = sheet,
range = "A1:B7",
col_names = c("key", "value"), col_types = "text")
x <- x[!is.na(x$key), ]
x <- list(device = x$value[grepl(pattern = "meettoestel", x$key, ignore.case = TRUE)],
gps = x$value[grepl(pattern = "meetpunt", x$key, ignore.case = TRUE)])
x$latlon <- as.numeric(unlist(strsplit(x$gps, split = ",")))
x$lat <- head(x$latlon, 1)
x$lon <- tail(x$latlon, 1)
x[c("device", "lat", "lon")]
x
}
read_one_measurements <- function(file, sheet){
units <- readxl::read_excel(path = file, sheet = 1, skip = 9, col_names = TRUE, n_max = 1, col_types = "text")
units <- as.list(units)
#range <- sprintf("A12:%s100000000", cellranger::num_to_letter(length(units)))
x <- readxl::read_excel(path = file, sheet = 1, skip = 10, guess_max = 10000#, col_names = names(units), range = range,
#col_types = c("text", "date", "text", rep("numeric", length(units) - 3))
)
x <- readxl::read_excel(path = file, sheet = 1, range = cell_limits("A:H"), skip = 11)
colnames(x) <- names(units)
}
lapply(sheets, FUN=function(sheet){
read_one_meta(fname, sheet)
})
if(tools::file_ext(fname) %in% "xls"){
}else if(tools::file_ext(fname) %in% "xlsx"){
x <- readxl::read_xlsx(path = fname, sheet = sheets[1], range = "A1:B7")
}
}
dashinput <- list()
dashinput$stationinfo <- content(GET("http://geo.irceline.be/sos/api/v1/stations?expanded=true"))
dashinput$meetstations <- lapply(dashinput$stationinfo, FUN=function(x){
data.frame(id = x$properties$id,
label = x$properties$label,
phenomena = sort(unique(sapply(x$properties$timeseries, FUN=function(x) x$phenomenon$label))), stringsAsFactors = FALSE)
})
dashinput$meetstations <- rbindlist(dashinput$meetstations)
#dashinput$meetstations[, list(phenomena = ), by = list(id)]
dashinput$region <- subset(BE_ADMIN_REGION, TX_RGN_DESCR_NL %in% "Vlaams Gewest")
dashinput$endpoint <- as.Endpoint("http://sosrest.irceline.be/api/v1")
dashinput$endpoint <- as.Endpoint("http://geo.irceline.be/sos/api/v1")
dashinput$srv <- fetch(services(dashinput$endpoint))
dashinput$stations <- stations(dashinput$endpoint, service = dashinput$srv)
dashinput$stations_sp <- as.SpatialPointsDataFrame(dashinput$stations)
dashinput$stations_sp <- dashinput$stations_sp[sapply(1:nrow(dashinput$stations_sp), FUN=function(idx) gIntersects(dashinput$region, dashinput$stations_sp[idx, ])), ]
```
```{r}
popups <- list()
popups$data_import <- modalDialog(title = "Data upload",
"Some information",
actionButton("uiInput_start", label = "OK", icon = icon("ok")),
footer = NULL, easyClose = FALSE)
```
# Data {data-icon="fa-cloud-upload"}
```{r child="pages_citizenair/page01-introduction.Rmd"}
```
# Exploreer en vergelijk {data-icon="fa-toggle-on"}
```{r child="pages_citizenair/page02-exploratory.Rmd"}
```
## Data
### Citizen Air - laadt je eigen metingen op {data-height=400}
```{r}
tags$h3("Citizen Air: meet - evalueer - vergelijk")
tags$blockquote("Deze toepassing laat je toe om de kwaliteit van je eigen luchtmeting in te schatten.
Hiervoor moet je je data plaatsen in het template dat je via", tags$a(href="https://hoemeetiklucht.eu", "www.hoemeetiklucht.eu"), "kan samenstellen.")
tags$ul(
tags$li("Download een voorbeeld excel file: ", tags$a(href="https://hoemeetiklucht.eu", "hoemeetiklucht.eu")),
tags$li("Download de handleiding: ", tags$a(href="https://hoemeetiklucht.eu", "hoemeetiklucht.eu"))
)
```
```{r}
fileInput("uiInput_xl", label = "Selecteer het bestand met uw metingen: ", accept = "application/excel",
buttonLabel = div("excel: ", icon("file-excel-o")), placeholder = "Nog geen bestand geselecteerd")
citizenair_userdata <- eventReactive(input$uiInput_xl, {
default <- data.frame(name = character(),
size = integer(),
type = character(),
datapath = character(),
stringsAsFactors = FALSE)
result <- list()
result$name <- input$uiInput_xl$name
result$file <- input$uiInput_xl$datapath
if(is.null(input$uiInput_xl)){
result$file <- default
}
result
})
```
### Meetstations van de Vlaamse Overheid {data-height=500}
```{r}
leafletOutput("uiOutput_stations")
output$uiOutput_stations <- renderLeaflet({
stations <- dashinput$stations_sp
map <- leaflet(data = dashinput$region) %>%
addTiles() %>%
addPolygons(weight = 3, fillOpacity = 0) %>%
addPolygons(weight = 3, fillOpacity = 0) %>%
addPopups(lng=4.366354, lat=50.86619, popup = "BNOSAC office")
map <- addCircleMarkers(map = map, data = stations,
radius = 5, opacity = 0.3, weight = 3,
popup = as.character(stations$label))
map
})
```
## Overall {data-width=150}
### Opgeladen meetpunt
```{r}
renderValueBox({
n <- 0
vb_icon <- NULL
vb_col <- NULL
if(n > 0){
vb_col <- "green"
vb_icon <- "fa-thumbs-up"
}
valueBox(n, caption = "Uw meetpunten", icon = vb_icon, color = vb_col)
})
```
```{r}
actionButton("uiInput_xl", label = "Toon je data", icon = icon("table"))
```
### Meetperiode
```{r}
showModal(popups$data_import)
renderPrint({
inputdata <- citizenair_userdata()
inputdata
})
```
### Meetperiode
Sequentie van metingen
bvb elke seconde / 5 seconden
### Polluenten
PM2.5
PM10
## Verken je metingen {.tabset}
### Toon je metingen
gemiddelde / mediaan / piek / dal
### Vergelijk met officiële metingen
### Is mijn meettoestel correct
## Inputs {data-width=150}
### Inputs
Laad een nieuwe file
```{r}
actionButton(inputId = "uiInput_refresh", label = "Refresh")
radioButtons(inputId = "uiInput_periode", label = "Period - shortcuts",
choices = c("Per seconde" = "Per seconde",
"Per minuut" = "Per minuut",
"Per 5 minuten" = "Per 5 minuten",
"Per uur" = "Per uur",
"Per dag" = "Per dag",
"Per week" = "Per week"),
selected = "Per minuut")
```
```{r}
materialSwitch(inputId = "ui_events_period_custom", label = "Custom period",
value = FALSE, status = "info")
dateRangeInput(inputId = "ui_events_period", label = "Custom period", start = Sys.Date(), end = Sys.Date()+1)
actionButton(inputId = "ui_events_start", label = "Refresh")
```
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
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