7.2.   R-Shiny App for Viewing Data in Real-Time

We recommend using this R-Shiny app for viewing your data in real-time, and if you wish to display your data publicly.

Plotting data using the R-Shiny app

Instructions for using the RShiny_flux_plots.R app (under /Biomet.net/R/RShiny_flux_plots/). To run the R-Shiny app, either locally or on an R-Shiny server, you will need to download, edit, rename and save two files.

  1. Download the Excel sheet below to input your site coordinates (you can include multiple sites, each as a separate line):

    Example site coordinate file

    • Note that the standard meridian is equal to your [UTC offset (without daylight savings) x 15]. For example, Vancouver is UTC-8 so the standard meridian is -120.

    • Also, latitude and longitude are in decimal degrees, and negative for West and South coordinates.

  2. Rename the Excel file to include your specific Project Name (in place of “TUT” in this example file).

  3. Create a new folder called RShiny_flux_plots_ini within <projectPath>/Database/Calculation_Procedures/, and save your Excel site coordinates file within this new folder.

  4. Next, download this R-Shiny ini file example:

    Example R-Shiny ini file

  5. Edit the ini file, renaming the two paths at the top of the file, to (a) the Biomet.net library and (b) your Database folder, so they match your local computer.

  6. Select which level(s) of data you would like to plot. You can plot ThirdStage data by specifying level <- "Clean/ThirdStage", or multiple levels of data using the concatenate command, e.g., level <- c("Clean/ThirdStage","Met").

  7. As with the Excel sheet, rename the ini file to include your specific Project Name and save it in under <projectPath>/Database/Calculation_Procedures/RShiny_flux_plots_ini/ (same location as the Excel file).

  8. Next, copy the code block below to a new R script, again saving it in your new RShiny_flux_plots_ini folder. You can name it as you wish; in this example it is named run_RShiny.R. Edit the filepaths at the top of your new script, as with your INI file, and also enter your RShiny ini filename. Alternatively, you can run these lines of code on the command line, but you must remember to edit the file paths and ini filename.

     # Edit these two file paths to point to biomet.net library and your database directory
     biomet_dir <- "/Users/rosie/Documents/Micromet/Biomet.net"  # path to Biomet.net directory 
     main_dir <- "/Users/rosie/Documents/Micromet/Projects/My_Micromet/Database"   # database path 
    
     # Edit to match your RShiny ini filename
     ini_filename <- "TUT_RShiny_ini.R"
    
     source(file.path(main_dir,"Calculation_Procedures/RShiny_flux_plots_ini",ini_filename))
     source(file.path(biomet_dir,"R/RShiny_flux_plots/load_save_data.R"))
     shiny::runApp(file.path(biomet_dir,"R/RShiny_flux_plots/RShiny_flux_plots.R"))
  9. You can now run the R-Shiny app by running your new script (run_RShiny.R), or as mentioned in step 9, you can run the individual lines of code within the R console. Importantly, remember to change the file paths to match those on your local computer.

Note: if you get an error installing the package imager, you may need to try:

For imager, you may need to download quartz to be able to run this library properly (https://www.xquartz.org) & then use install.packages("igraph", type="binary")