myClimGui-tutorial.Rmd
Interactive browsing of myClim objects. The main interactive menu consists of:
# === First install dependencies ===
requiered_packages <- c("purrr", "stringr", "lubridate", "ggplot2", "plotly",
"myClim", "shiny", "shinyjs", "dplyr", "DT",
"tibble", "shinythemes", "callr", "RColorBrewer")
missing_packages <- requiered_packages[!(requiered_packages %in% installed.packages()[,"Package"])]
if(length(missing_packages)) install.packages(missing_packages)
if(!("shinyTree" %in% installed.packages()[,"Package"])) {
remotes::install_github("shinyTree/shinyTree")
}
# === Install myClimGui ===
install.packages("http://labgis.ibot.cas.cz/myclim/myClimGui_latest.tar.gz",
repos=NULL, build_vignettes=TRUE)
On the left side of the running Shiny myClimGui, you can see a tree structure of your localities, loggers, and sensors. Here, you can select which time-series you wish to browse in the viewer. Only selected time-series are shown. After selecting the localities/loggers/sensors you wish to browse, you have to hit the Show button.
There are several options in Plot mode, including Multi Select, Plotly, and Color by Logger in the left panel. On the right side of the screen, you can also set the time span of the data you wish to browse, i.e., limit the plot region to certain dates.
You can use the dropdown menu at the top of the screen to drive the facet options. You can choose to facet by physical, locality, or NULL.
When you draw a rectangle (select region) with the mouse in the plotting window and double-click in the selected region, the plot will zoom in. You can zoom multiple times. To return to see the full data range, you can hit refresh on the right-hand side or double-click outside the selected region.
When you wish to select specific sensors across all localities, you can filter them in Sensors window above the localities/loggers/sensors tree.You can edit the text of the tag in the table after double-clicking the cell, the same as the text of the value.
You can also edit the range of the tag by clicking the “edit range” button and selecting a new start/end from the popup calendar.You can also add a new tag by clicking the “New” button, where you specify the start, end, and tag. Note, that adding a new state will apply it to all sensors selected in the Plot section.
To save your edits (editing states) you need to send
mcg_run()
into the new object. After your edits, hit
Return. This will create new object in R environment including
your edits.
# === Saving your edits ===
# edit states, hit "return", save modified object into R environment.
states.edit <- myClimGui::mcg_run(myClim::mc_data_example_agg)
# === Browsing only, no edits saving ===
myClimGui::mcg_run(myClim::mc_data_example_agg)
Normally, when you run a Shiny app from RStudio, the console
“freezes” as it executes commands from Shiny. To avoid this behavior,
you can use the mcg_run_bg
function, which is a wrapper for
the parallel console from the callr
package. This allows
you to open your web browser, use myClimGui there, and still be
able to work in RStudio as usual, without any freezing. To retrieve your
modified object, you need to query the environment by calling
$get_result()
.
# launch process in web browser
proc <- myClimGui::mcg_run_bg(myClim::mc_data_example_agg)
# retrieve the result after click Return button
data <- proc$get_result()
mcg_run
and Shiny starts, the RStudio
console is “frozen,” handling commands from Shiny. You are not able to
work in the console simultaneously with running Shiny. If you wish to
work in consle and the same time run Shiny app use function
mcg_run_bg
.