Commit c291b99e by Jan Wijffels

redesign page 2

parent 42a72a11
......@@ -26,10 +26,12 @@ library(sp)
library(xts)
library(dygraphs)
data("BE_ADMIN_REGION", package = "BelgiumMaps.StatBel")
data("ca", package = "citizenair")
dashinput <- list()
dashinput$endpoint <- as.Endpoint("http://geo.irceline.be/sos/api/v1")
dashinput$appdata <- CitizenAir$new(endpoint = dashinput$endpoint)
#dashinput$appdata <- CitizenAir$new(endpoint = dashinput$endpoint)
dashinput$appdata <- ca
dashinput$region <- subset(BE_ADMIN_REGION, TX_RGN_DESCR_NL %in% "Vlaams Gewest")
dashinput$stations_sp <- dashinput$appdata$getStations()
dashinput$stations_sp <- dashinput$stations_sp[sapply(1:nrow(dashinput$stations_sp),
......@@ -47,6 +49,58 @@ popups$cleaned_data <- modalDialog(
tags$hr(),
DT::dataTableOutput("uiOutput_rawdata", width = "100%", height = "auto"),
size = "l", footer = modalButton("Sluit"), easyClose = TRUE)
citizenair_userdata <- reactive({
input$uiInput_xl
isolate({
default <- data.frame(name = character(), size = integer(), type = character(), datapath = character(), stringsAsFactors = FALSE)
result <- list()
result$stations <- dashinput$stations_sp
result$name <- input$uiInput_xl$name
result$file <- input$uiInput_xl$datapath
result$data <- list()
result$data$phenomena <- character()
result$data$meta <- data.frame(sheet_id = integer(), sheet = character(), device = character(),
lat = numeric(), lon = numeric(),
phenomena = character(), stringsAsFactors = FALSE)
result$data$phenomena <- data.frame(sheet_id = integer(), time = as.POSIXct(character()), date = as.Date(character()),
phenomena = character(), value = numeric(), stringsAsFactors = FALSE)
if(is.null(input$uiInput_xl)){
result$file <- default
}else{
showNotification("We lezen uw Excel bestand in wacht even...")
x <- try(dashinput$appdata$setCitizenData(result$file))
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)))
}else{
x <- dashinput$appdata$data
result$data$polluenten <- x$phenomena
result$data$meta <- as.data.frame(x, type = "meta")
result$data$phenomena <- as.data.frame(x, type = "measurements")
nearest_station <- function(stations, x){
d <- sp::spDistsN1(stations, x, longlat = TRUE)
stations[which.min(d), ]
}
point <- as.matrix(data.frame(lon = 51.20, lat = 4.54))
point <- subset(result$data$meta, !is.na(lon))
if(nrow(point) > 0){
result$nearest_station <- nearest_station(stations = dashinput$stations_sp, as.matrix(point[1, c("lon", "lat")]))
result$nearest_station <- result$nearest_station$id
}else{
result$nearest_station <- character()
}
output$uiOutput_rawmeta <- renderTable(result$data$meta)
output$uiOutput_rawdata <- renderDT(datatable(result$data$phenomena, rownames = FALSE,
caption = 'Overzicht van alle meetgegevens per sheet/tijdstip/type meting',
filter = 'top', options = list(pageLength = 5, autoWidth = TRUE)))
showModal(popups$cleaned_data)
}
}
})
result
})
```
# Data {data-icon="fa-cloud-upload"}
......
......@@ -13,70 +13,23 @@ output[["citizenair-blank.xls"]] <- downloadHandler(
)
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.")
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: ", downloadLink("citizenair-example.xls", "citizenair-example.xls")),
tags$li("Download een lege excel file waarin je je data kan copy-pasten: ", downloadLink("citizenair-blank.xls", "citizenair-blank.xls")),
tags$li("Download de handleiding: ", tags$a(href="https://hoemeetiklucht.eu", "hoemeetiklucht.eu"))
tags$li("Download een voorbeeld excel file: ",
downloadLink("citizenair-example.xls", "citizenair-example.xls")),
tags$li("Download een lege excel file waarin je je data kan copy-pasten: ",
downloadLink("citizenair-blank.xls", "citizenair-blank.xls")),
tags$li("Ga naar 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 <- reactive({
input$uiInput_xl
isolate({
default <- data.frame(name = character(), size = integer(), type = character(), datapath = character(), stringsAsFactors = FALSE)
result <- list()
result$stations <- dashinput$stations_sp
result$name <- input$uiInput_xl$name
result$file <- input$uiInput_xl$datapath
result$data <- list()
result$data$phenomena <- character()
result$data$meta <- data.frame(sheet_id = integer(), sheet = character(), device = character(),
lat = numeric(), lon = numeric(),
phenomena = character(), stringsAsFactors = FALSE)
result$data$phenomena <- data.frame(sheet_id = integer(), time = as.POSIXct(character()), date = as.Date(character()),
phenomena = character(), value = numeric(), stringsAsFactors = FALSE)
if(is.null(input$uiInput_xl)){
result$file <- default
}else{
showNotification("We lezen uw Excel bestand in wacht even...")
x <- try(dashinput$appdata$setCitizenData(result$file))
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)))
}else{
x <- dashinput$appdata$data
result$data$polluenten <- x$phenomena
result$data$meta <- as.data.frame(x, type = "meta")
result$data$phenomena <- as.data.frame(x, type = "measurements")
nearest_station <- function(stations, x){
d <- sp::spDistsN1(stations, x, longlat = TRUE)
stations[which.min(d), ]
}
point <- as.matrix(data.frame(lon = 51.20, lat = 4.54))
point <- subset(result$data$meta, !is.na(lon))
if(nrow(point) > 0){
result$nearest_station <- nearest_station(stations = dashinput$stations_sp, as.matrix(point[1, c("lon", "lat")]))
result$nearest_station <- result$nearest_station$id
}else{
result$nearest_station <- character()
}
output$uiOutput_rawmeta <- renderTable(result$data$meta)
output$uiOutput_rawdata <- renderDT(datatable(result$data$phenomena, rownames = FALSE,
caption = 'Overzicht van alle meetgegevens per sheet/tijdstip/type meting',
filter = 'top', options = list(pageLength = 5, autoWidth = TRUE)))
showModal(popups$cleaned_data)
}
}
})
result
})
#materialSwitch(inputId = "uiInput_addexcel", label = "Combineer excel met vorige excel", value = FALSE, status = "info")
```
### Meetstations van de Vlaamse Overheid {data-height=500}
......@@ -91,16 +44,17 @@ output$uiOutput_stations <- renderLeaflet({
map <- addTiles(map)
map <- addPolygons(map, weight = 3, fillOpacity = 0)
map <- addCircleMarkers(map = map, data = stations, radius = 5, opacity = 0.3, fillOpacity = 1, weight = 3,
popup = as.character(mapply(label = stations$label, phenomena = stations$phenomena_label,
FUN=function(label, phenomena){
sprintf("<b>Station: %s</b> <br>Meetwaardes:<br> %s", label, paste(sprintf(" - %s ", phenomena), collapse = "<br>"))
popup = as.character(mapply(id = stations$id, label = stations$label, phenomena = stations$phenomena_label,
FUN=function(id, label, phenomena){
sprintf("<b>Station %s: %s</b> <br>Meetwaardes:<br> %s", id, label, paste(sprintf(" - %s ", phenomena), collapse = "<br>"))
})))
if(length(userdata$nearest_station) > 0){
stations <- subset(stations, id %in% userdata$nearest_station)
map <- addPopups(map, data = stations, popup = "Dichtstbijzijnd gevalideerd meetstation")
stations <- head(stations, 1)
map <- addPopups(map, data = stations, popup = sprintf("Dichtste meetstation<br>%s: %s", stations$id, stations$label))
}
if(nrow(meta) > 0){
map <- addPopups(map, lng = meta$lon, lat = meta$lat, popup = "Uw meetpunten")
map <- addPopups(map, lng = meta$lon, lat = meta$lat, popup = sprintf("<b>Sheet %s: %s</b>", meta$sheet_id, meta$sheet))
map <- addCircleMarkers(map, lng = meta$lon, lat = meta$lat, color = "red",
popup = sprintf("Sheet: %s\nDevice: %s", meta$sheet, meta$device),
radius = 5, weight = 3, fillOpacity = 1)
......@@ -192,7 +146,7 @@ renderTable({
x <- x[order(n, decreasing=TRUE), ]
x <- merge(x, userdata$data$meta, by = "sheet_id")
x <- as.data.frame(x)
x <- x[!duplicated(x$sheet_id), c("sheet_id", "device", "meetfrequentie", "n", "pct")]
x <- x[!duplicated(x$sheet_id), c("sheet_id", "device", "meetfrequentie")]
x$meetfrequentie <- sprintf("elke %s minuten", round(x$meetfrequentie, 2))
}else{
x <- NULL
......
## Sidebar {.sidebar}
#### Selectiecriteria
```{r}
actionBttn(inputId = "uiInput_selectstation", label = "Vergelijk met ander officieel station", style = "gradient")
```
```{r}
radioButtons(inputId = "uiInput_periode", label = "Vergelijk op basis van",
choices = c("Per minuut" = "minute", "Per uur" = "hour", "Per dag" = "day", "Per maand" = "month"),
selected = "day")
dateRangeInput(inputId = "uiInput_period", label = "Verander de periode", start = Sys.Date()-365, end = Sys.Date())
actionButton(inputId = "uiInput_refresh", label = "Herbereken")
```
## Verken je metingen {.tabset}
### Toon je metingen
### Verken je metingen
Hieronder tonen we een overzicht van jouw meting en de dichtstbijzijnde VMM-meetplaats in
functie van de tijd. Verken je meting hieronder en kijk eens wat er gebeurt als je uitmiddelt per
uur, per dag enz. Als je een goed zicht hebt op je data, ga dan naar de volgende stap.
```{r}
x <- dashinput$appdata$fetch_timeseries("1030")
......@@ -14,32 +33,57 @@ g <- dyRangeSelector(g, height = 20)
g
```
### Vergelijk met officiële metingen
### Vergelijk met officieel meetstation
### 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")
renderValueBox({
userdata <- citizenair_userdata()
stations <- userdata$stations
stations <- subset(stations, id %in% userdata$nearest_station)
if(nrow(stations) > 0){
ui <- valueBox(stations$label, caption = "Vergelijk met officieel meetstation")
}else{
ui <- NULL
}
ui
})
```
###
```{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")
renderValueBox({
filename <- citizenair_userdata()$name
if(length(filename) > 0){
ui <- valueBox("Uw excel file", caption = citizenair_userdata()$name)
}else{
ui <- NULL
}
ui
})
```
###
```{r}
renderUI({
userdata <- citizenair_userdata()
x <- userdata$data$meta
if(is.data.frame(x) && nrow(x) > 0){
choices <- as.list(x$sheet_id)
names(choices) <- x$sheet
ui <- selectInput(inputId = "uiInput_sheet", label = "Selecteer sheet", choices = choices, selected = choices, multiple = TRUE)
}else{
ui <- NULL
}
ui
})
```
\ No newline at end of file
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