Commit 7d5c0888 by Jan Wijffels

Add more tabs with dev plots

parent cf36f4ec
......@@ -22,7 +22,7 @@ run_app('citizenair.Rmd')
install.packages(c('flexdashboard', 'shiny', 'shinyWidgets', 'rmarkdown', 'DT'))
install.packages(c('data.table', 'httr', 'readxl', 'magrittr', 'cellranger', 'fasttime'))
install.packages(c('leaflet', 'sp', 'rgeos'))
install.packages(c('dygraphs', 'xts'))
install.packages(c('dygraphs', 'xts', 'openair', 'ggplot2'))
devtools::install_github('bnosac/BelgiumMaps.Statbel')
devtools::install_github('52North/sensorweb4R')
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/')"
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('leaflet', 'sp', 'rgeos'), repos='https://cloud.r-project.org/')"
RUN R -e "install.packages(c('dygraphs', 'xts'), repos='https://cloud.r-project.org/')"
RUN R -e "install.packages(c('dygraphs', 'xts', 'openair', 'ggplot2'), repos='https://cloud.r-project.org/')"
RUN R -e "devtools::install_github('bnosac/BelgiumMaps.Statbel')"
RUN R -e "devtools::install_github('52North/sensorweb4R')"
RUN git -c http.sslVerify=false clone https://www.datatailor.be/vmm/citizenair
......
---
title: "Citizen Air: meet - evalueer - vergelijk"
title: "Citizen Air - meet - evalueer - vergelijk"
runtime: shiny
output:
flexdashboard::flex_dashboard:
......@@ -25,13 +25,15 @@ library(DT)
library(sp)
library(xts)
library(dygraphs)
library(ggplot2)
library(openair)
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 <- ca
dashinput$appdata <- 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$stations_sp <- dashinput$appdata$getStations()
dashinput$stations_sp <- dashinput$stations_sp[sapply(1:nrow(dashinput$stations_sp),
......@@ -103,6 +105,32 @@ citizenair_userdata <- reactive({
})
```
```{r}
## DEV APP SETTINGS
reactive <- reactiveValues()
plots <- reactiveValues()
mydata <- data.frame(date = as.POSIXct(seq.Date(Sys.Date(), Sys.Date()-999, by = "-1 day"), tz = "UTC"),
REF = rnorm(1000),
SENSOR = rnorm(1000))
linear_model <- lm(mydata$SENSOR ~ mydata$REF)
PI <- data.frame(predict(linear_model, interval="predict", level = 0.95))
colnames(PI) <- c("OLSQ", "lower PI", "upper PI")
CI <- data.frame(predict(linear_model, interval="confidence", level = 0.95))
colnames(CI) <- c("OLSQ", "lower CI", "upper CI")
mydata <- cbind(mydata, "OLSQ" = CI$OLSQ,"lower_CI" = CI$`lower CI`, "upper_CI"=CI$`upper CI`, "lower_PI" = PI$`lower PI`, "upper_PI" = PI$`upper PI`)
mydata$e <- mydata$OLSQ - mydata$SENSOR
mydata <- mydata[order(mydata[,1]), ]
summary <- data.frame(do.call(cbind, lapply(mydata, summary)))[-7,]
summary$date <- as.character(as.POSIXct(summary$date, origin="1970-01-01"))
summary <- rbind(summary,"# Valid"=colSums(!is.na(mydata)))
summary <- rbind(summary,"# NA's"=colSums(is.na(mydata)))
variables <- c("min", "25th Perc", "median", "mean","75th Perc", "max","# Valid", "# NA's")
summary <- cbind("variable"=variables,summary)
reactive[["linear_model"]] <- linear_model
reactive[["regData"]]<- mydata
reactive[["summaryRaw"]] <- summary
```
# Data {data-icon="fa-cloud-upload"}
```{r child="page01-introduction.Rmd", eval=TRUE}
......
......@@ -21,7 +21,7 @@ tags$ul(
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$li("Ga naar de handleiding op ",
tags$a(href="https://hoemeetiklucht.eu", "hoemeetiklucht.eu"))
)
```
......
......@@ -55,9 +55,79 @@ output$uiOutput_select_station <- renderLeaflet({
```
### Is mijn meettoestel correct
### Meet mijn meettoestel zoals een officieel toestel
```{r}
fillCol(
tags$div(
tags$h4("De Vlaamse Milieu Maatschappij heeft meetresultaten die aan de strengste kwaliteitseisen voldoen. Hieronder tonen
we een eenvoudige statistische vergelijking tussen onze meetgegevens en die van jouw. Verander ook de VMM-meetplaats eens, een andere meetplaats komt misschien beter me de jouwe overeen!"),
tags$h5("Onderstaande grafiek toont alle meetwaardes van uw toestel uitgezet tov alle meetwaardes van een toestel van de Vlaamse Milieu Maatschappij")),
fillRow(dropdownButton(
tags$h3("Selectie dagen van de week"),
radioButtons(inputId = "uiInput_dayofweek", label = "Vergelijk op basis van",
choices = c("Alle dagen van de week" = "all", "Enkel weekdagen" = "weekdays", "Enkel weekend" = "weekend"),
selected = "all"),
tags$h3("Input voor de grafiek"),
sliderInput(inputId = "uiInput_slider", label = "TODO", value = 25, min = 5, max = 100, step = 1L, round = TRUE),
circle = TRUE, status = "info", icon = icon("gear"), width = "300px", size = "sm",
tooltip = tooltipOptions(title = "Verdere opties")),
plotOutput("uiOutput_comparison", height = "100%"),
flex = c(NA, 2)
),
flex = c(NA, 2)
)
# Scatterplot of linear regression + CI & PI
output$uiOutput_comparison <- renderPlot({
req(c(reactive$regData,reactive$linear_model))
mydata <- reactive$regData
linear_model <- reactive$linear_model
plot_PI_CI <- ggplot(data = mydata, aes(x = REF, y = SENSOR)) +
geom_ribbon(aes(ymin = lower_CI, ymax=upper_CI, fill = "CI"),alpha = 0.6) +
geom_ribbon(aes(ymin = lower_PI, ymax=upper_PI, fill = "PI"), alpha = 0.4) +
geom_point() +
geom_line(aes(y = OLSQ,col = "OLSQ")) +
geom_line(aes(y = REF,col = "y=x")) +
labs(title = paste("Scatterplot with regression estimates: intercept =",
format(summary(linear_model)$coefficients[1,1], digits = 3),
",slope =",format(summary(linear_model)$coefficients[2,1], digits = 3),
",R² =",format(summary(linear_model)$r.squared, digits = 3)),
x = "Reference value",
y = "Sensor") +
scale_fill_manual(name="",values=c("CI"="blue","PI"= "grey")) +
scale_colour_manual(name="", values = c("y=x"="red","OLSQ"="black"))
plots[["scatter"]] <- plot_PI_CI
plot_PI_CI
})
```
### Gevorderd overzicht van de vergelijking
```{r}
fillCol(
tableOutput("data"),
tags$hr(),
tableOutput("summaryRaw"),
flex = c(1, NA, 1)
)
```
```{r}
# outputs of dataframe & summaries
output$data <- renderTable({
req(reactive[["regData"]])
mydata <- reactive[["regData"]]
avg.time <- "day"
mydata <- timeAverage(mydata, avg.time=avg.time, data.thresh=85,statistic="mean")
mydata$date <- as.character(as.POSIXct(mydata$date, origin="1970-01-01"))
mydata})
output$summaryRaw <- renderTable({reactive[["summaryRaw"]]})
output$summaryValid <- renderTable({reactive[["summaryValid"]]})
```
## Inputs {data-width=150}
###
......
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