library(RMySQL) library(ggplot2) library(ggforce) library(dplyr) library(aquanes.report) thresholds_file <- system.file("shiny/berlin_s/data/thresholds.csv", package = "aquanes.report") thresholds <- aquanes.report::get_thresholds(csv_path = thresholds_file ) if (params$run_as_standalone) { ### Raw data raw_dat <- aquanes.report::import_data_berlin_s() calc_dat <- aquanes.report::calculate_operational_parameters_berlin_s(df = raw_dat) dat <- plyr::rbind.fill(raw_dat, calc_dat) conf_template <- aquanes.report::report_config_template(df = dat, temporal_aggregation = "raw", output_timezone = "Europe/Berlin") aquanes.report::report_config_to_txt(config_list = conf_template, "report_config_template.txt") report_config_path <- file.path(getwd(), "report_config.txt") if (file.exists(report_config_path)) { ### Import & use report configuration from "report_config.txt" input <- aquanes.report::report_txt_to_config(report_config_path) } else { ### Set a dummy configuration in case no "report_config.txt" exists input <- list(report_sitenames = unique(dat$SiteName), report_aggregation = "day", report_parameters_online = unique(dat$ParameterName[dat$Source == "online"])[1], #report_parameters_offline = unique(dat$ParameterName[dat$Source == "offline"])[6], report_add_thresholds = FALSE, report_daterange = c("2017-07-01", "2017-07-31"), report_timezone = "CET") } ### Aggregate to user defined time period if (input$report_aggregation != "raw") { dat <- aquanes.report::group_datetime(dat, by = input$report_aggregation) } date_idx <- as.Date(dat[,"DateTime"]) >= input$report_daterange[1] & as.Date(dat[,"DateTime"]) <= input$report_daterange[2] site_idx <- dat[,"SiteName"] %in% input$report_sitenames para_idx <- dat[,"ParameterName"] %in% c(input$report_parameters_online, input$report_parameters_offline) row_idx <- date_idx & site_idx & para_idx config <- list(run_as_standalone = TRUE, report_tz = aquanes.report::change_timezone(dat,tz = input$report_timezone)[date_idx,], report_data = aquanes.report::change_timezone(dat[row_idx,],tz = input$report_timezone), report_aggregation = input$report_aggregation, report_sitenames = input$report_sitenames, report_parameters_online = input$report_parameters_online, report_parameters_offline = input$report_parameters_offline, report_parameters_calculated = NA, report_add_thresholds = input$report_add_thresholds, report_daterange = input$report_daterange, report_timezone = input$report_timezone ) } else { config <- list(run_as_standalone = params$run_as_standalone, report_tz = params$report_tz, report_data = params$report_data, report_aggregation = params$report_aggregation, report_sitenames = params$report_sitenames, report_parameters_online = params$report_parameters_online, report_parameters_offline = params$report_parameters_offline, report_parameters_calculated = params$report_parameters_calculated, report_add_thresholds = params$report_add_thresholds, report_daterange = params$report_daterange, report_timezone = params$report_timezone) } #table_thresholds <- aquanes.report::check_thresholds(df = config$report_tz, # thresholds = thresholds)
r config$report_daterange[1]
- r config$report_daterange[2]
)Here are the time series plots for the reporting period from r config$report_daterange[1]
to r config$report_daterange[2]
using the timezone "r config$report_timezone
" with the following temporal aggregation
level (i.e. median values): "r config$report_aggregation
"
Nothing defined yet !
#knitr::kable(x = table_thresholds, # row.names = FALSE)
You selected the following r length(config$report_parameters_online)
parameter(s) for plotting:
r paste("* ", config$report_parameters_online,collapse = " \n")
At the following r length(config$report_sitenames)
sampling location(s):
r paste("* ", config$report_sitenames,collapse = " \n")
online <- config$report_data[config$report_data[,"ParameterName"] %in% config$report_parameters_online,] %>% dplyr::mutate_(label = "sprintf('%s (%s)',ParameterName, ParameterUnit)") for (i in seq_along(config$report_parameters_online)) { sel_par1 <- config$report_parameters_online[order(config$report_parameters_online)][i] n_measurements <- nrow(online[online[,"ParameterName"] == sel_par1,]) if (n_measurements > 0) { g1 <- ggplot2::ggplot(online, ggplot2::aes_string(x = "DateTime", y = "ParameterValue", col = "SiteName")) + ggforce::facet_wrap_paginate(~label, nrow = 1, ncol = 1, scales = "free_y", page = i) + ggplot2::geom_point() + ggplot2::theme_bw(base_size = 20) + ggplot2::theme(legend.position = "top" , strip.text.x = element_text(face = "bold") , legend.title = element_blank() ) + ggplot2::labs(x = "", y = "") if (config$report_add_thresholds == TRUE & sel_par1 %in% unique(thresholds$ParameterName)) { sel_threshold1 <- thresholds[thresholds$ParameterName == sel_par1,] g1 <- g1 + ggplot2::geom_hline(yintercept = sel_threshold1$ParameterThreshold, linetype = "dashed") } print(g1) } }
You selected the following r length(config$report_parameters_offline)
parameter(s) for plotting:
r paste("* ", config$report_parameters_offline,collapse = " \n")
At the following r length(config$report_sitenames)
sampling location(s):
r paste("* ", config$report_sitenames,collapse = " \n")
offline <- config$report_data[config$report_data[,"ParameterName"] %in% config$report_parameters_offline,] %>% dplyr::mutate_(label = "sprintf('%s (%s)',ParameterName, ParameterUnit)") for (i in seq_along(config$report_parameters_offline)) { sel_par2 <- config$report_parameters_offline[order(config$report_parameters_offline)][i] n_measurements <- nrow(offline[offline[,"ParameterName"] == sel_par2,]) if (n_measurements > 0) { g2 <- ggplot2::ggplot(offline, ggplot2::aes_string(x = "DateTime", y = "ParameterValue", col = "SiteName")) + ggforce::facet_wrap_paginate(~label, nrow = 1, ncol = 1, scales = "free_y", page = i) + ggplot2::geom_point() + ggplot2::geom_line() + ggplot2::theme_bw(base_size = 20) + ggplot2::theme(legend.position = "top" , strip.text.x = element_text(face = "bold") , legend.title = element_blank() #, axis.title = element_text(colour="black", size = 20) #, axis.text = element_text(colour="black", size = 20) ) + ggplot2::labs(x = "", y = "") if (config$report_add_thresholds == TRUE & sel_par2 %in% unique(thresholds$ParameterName)) { sel_threshold2 <- thresholds[thresholds$ParameterName == sel_par2,] g2 <- g2 + ggplot2::geom_hline(yintercept = sel_threshold2$ParameterThreshold, linetype = "dashed") } print(g2) } }
Not implemented yet!
Not implemented yet!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.