knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) url_defined <- Sys.getenv("MBR40_URL") != ""
# Install latest stable version from KWB-R R-Universe options(repos = c( kwbr = 'https://kwb-r.r-universe.dev', CRAN = 'https://cloud.r-project.org')) install.packages('kwb.pilot')
For downloading the latest
(from Martin Systems webportal
) and archived
(from
KWB Nextcloud
) .tsv
data files you need set the following environment variables
only once as shown below.
For doing so follow the steps below:
Open RStudio
and run usethis::edit_r_environ()
In the opened window add the required environment variables
MBR40_URL = "url-to-download-pilot-plant-data" NEXTCLOUD_URL = "https://<replace-with-dwc-cloud-url>" NEXTCLOUD_USER = "<your-dwc-cloud-username>" # your username NEXTCLOUD_PASSWORD = "your-nextcloud-app-password" ### see details below
To access the archived
data you need to be a registered Nextcloud user with
access to the folder projects/MBR4.0
For creating <your-nextcloud-app-password>
:
go to: https://replace-with-kwb-cloud-url/index.php/settings/user/security
scroll down to create new app password
select a name e.g. r-script
and copy the token and replace your-nextcloud-app-password
Finally you need to restart Rstudio and proceed with the code below:
Subsequently click Save and restart RStudio.
For running the shiny app it is needed to setup the environment variables as shown above and run the following code.
To use the latest data
(downloads data from web) or if you run the app for the first time you need to run:
kwb.pilot::run_app("mbr4.0", use_live_data = TRUE)
Once you have done the step above for one time, you can also just interactively load you datasets, which you downloaded during the command above by running:
kwb.pilot::run_app("mbr4.0", use_live_data = FALSE)
For performing data aggregation and export to post-process the data in Excel
in a wide
format the workflow defined
below has to be followed.
In paths_list
you need to replace the dummy value kwb-server
for the key servername
.
#KWB server paths_list <- list( servername = "kwb-server", root = "//<servername>/projekte$/WWT_Department/Projects/MBR 4.0/Exchange/", rawdata = "<root>/20_rawdata", processing = "<root>/21_processing", online = "<rawdata>/online_data", export_dir = "<processing>/online-data" ) if(dir.exists(paths$online)) { paths <- kwb.utils::resolve(paths_list) }
paths_list <- list( root = "C:/kwb/projects/mbr4.0", rawdata = "<root>/20_rawdata", processing = "<root>/21_processing", online = "<rawdata>/online_data", export_dir = "<processing>/online-data" ) # Only execute "At Home" if not at "KWB" (i.e. KWB server path does not exist) fs::dir_create(paths$online, recurse = TRUE) paths <- kwb.utils::resolve(paths_list)
library(kwb.pilot) mbr4_data_raw <- kwb.pilot::read_mbr4() str(mbr4_data_raw) mbr4_data_tidy_raw <- kwb.pilot::tidy_mbr4_data(mbr4_data = mbr4_data_raw) str(mbr4_data_tidy_raw)
mbr4_data_tidy_10min <- mbr4_data_tidy_raw %>% kwb.pilot::group_datetime(by = 600) mbr4_data_tidy_hour <- mbr4_data_tidy_10min %>% kwb.pilot::group_datetime(by = 3600)
Raw and aggregated data will be exported as csv
in wide
format (by running kwb.pilot::long_to_wide()
) as shown below:
kwb.pilot::export_data(df_long = mbr4_data_tidy_raw, export_dir = paths$export_dir) kwb.pilot::export_data(df_long = mbr4_data_tidy_list_10min, export_dir = paths$export_dir) kwb.pilot::export_data(df_long = mbr4_data_tidy_list_hour, export_dir = paths$export_dir)
Finally you can check the datasets in the export folder by running:
kwb.utils::hsOpenWindowsExplorer(paths$export_dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.