@@ -9,26 +9,28 @@ library(shinythemes)
99
1010source(' render-site-map.R' )
1111
12- # set up scheduled execution of cache update
13- # cache_update_cmd <- cron_rscript('cache-refresh.R')
14- # try(cron_add(command = cache_update_cmd, frequency = 'daily',
15- # id = 'cache-update', description = 'daily update of BETYdb cache'))
12+ # schedule daily execution of cache refresh
13+ cache_update_cmd <- cron_rscript(' cache-refresh.R' )
14+ try(cron_add(command = cache_update_cmd , frequency = ' daily' ,
15+ id = ' cache-update' , description = ' daily update of BETYdb cache' ))
1616
1717# set page UI
18- ui <- fluidPage( theme = shinytheme(' flatly' ),
18+ ui <- fluidPage(theme = shinytheme(' flatly' ),
1919
2020 tags $ link(rel = ' stylesheet' , type = ' text/css' , href = ' style.css' ),
2121 title = ' TERRA-REF Experiment Data' ,
2222
2323 tags $ img(src = ' logo.png' , class = ' push-out' ),
2424
25+ # destination for all dynamic UI elements
2526 uiOutput(' page_content' )
2627)
2728
29+ # render UI for a given season
2830render_season_ui <- function (season_name ) {
2931
3032 tabPanel(season_name ,
31-
33+
3234 sidebarPanel(class = ' push-down' ,
3335 uiOutput(paste0(' variable_select_' , season_name )),
3436 uiOutput(paste0(' cultivar_select_' , season_name ))
@@ -58,6 +60,7 @@ render_season_ui <- function(season_name) {
5860 )
5961}
6062
63+ # render selection menu from available variables in a given season
6164render_variable_menu <- function (season_name , output , full_cache_data ) {
6265
6366 variable_names <- names(full_cache_data [[ season_name ]][[ ' trait_data' ]])
@@ -67,6 +70,7 @@ render_variable_menu <- function(season_name, output, full_cache_data) {
6770 })
6871}
6972
73+ # render selection menu from available cultivars in a given season, for the selected variable
7074render_cultivar_menu <- function (season_name , input , output , full_cache_data ) {
7175
7276 output [[ paste0(' cultivar_select_' , season_name ) ]] <- renderUI({
@@ -80,6 +84,8 @@ render_cultivar_menu <- function(season_name, input, output, full_cache_data) {
8084 })
8185}
8286
87+ # render box plot time series from trait records in a given season, for the selected variable
88+ # if a cultivar is selected, render line plot from trait records for that cultivar
8389render_trait_plot <- function (season_name , input , output , full_cache_data ) {
8490
8591 output [[ paste0(' trait_plot_' , season_name ) ]] <- renderPlot({
@@ -99,7 +105,6 @@ render_trait_plot <- function(season_name, input, output, full_cache_data) {
99105 if (units != ' ' )
100106 title <- paste0(selected_variable , ' (' , units , ' )' )
101107
102- # generate timeseries of boxplots from mean value
103108 ggplot(plot_data , aes(as.Date(date ), mean )) +
104109 geom_boxplot(aes(group = cut_width(as.Date(date ), 1 )), outlier.alpha = 0.1 ) +
105110
@@ -123,6 +128,7 @@ render_trait_plot <- function(season_name, input, output, full_cache_data) {
123128 })
124129}
125130
131+ # render timeline from management records in a given season
126132render_mgmt_timeline <- function (season_name , input , output , full_cache_data ) {
127133
128134 output [[ paste0(' mgmt_timeline_' , season_name ) ]] <- renderTimevis({
@@ -148,6 +154,7 @@ render_mgmt_timeline <- function(season_name, input, output, full_cache_data) {
148154 })
149155}
150156
157+ # render info box for date and value of cursor when hovering box/line plot
151158render_plot_hover <- function (season_name , input , output , full_cache_data ) {
152159
153160 output [[ paste0(' plot_hover_info_' , season_name ) ]] <- renderUI({
@@ -170,6 +177,7 @@ render_plot_hover <- function(season_name, input, output, full_cache_data) {
170177 })
171178}
172179
180+ # render info box for date, type, and notes of selected (clicked) timeline item
173181render_timeline_hover <- function (season_name , input , output , full_cache_data ) {
174182
175183 output [[ paste0(' mgmt_select_info_' , season_name ) ]] <- renderUI({
@@ -196,13 +204,15 @@ render_timeline_hover <- function(season_name, input, output, full_cache_data) {
196204
197205render_map <- function (season_name , input , output , full_cache_data ) {
198206
207+ # render slider input from dates in a given season
199208 output [[ paste0(' map_date_slider_' , season_name ) ]] <- renderUI({
200209 sliderInput(paste0(' map_date_' , season_name ), ' Date' ,
201210 as.Date(full_cache_data [[ season_name ]][[ ' start_date' ]]),
202211 as.Date(full_cache_data [[ season_name ]][[ ' end_date' ]]),
203212 as.Date(full_cache_data [[ season_name ]][[ ' end_date' ]]))
204213 })
205214
215+ # render heat map of sites from trait records in a given season, for the selected date, variable and cultivar
206216 output [[ paste0(' site_map_' , season_name ) ]] <- renderLeaflet({
207217
208218 req(input [[ paste0(' selected_variable_' , season_name ) ]])
@@ -227,7 +237,7 @@ render_map <- function(season_name, input, output, full_cache_data) {
227237 })
228238}
229239
230-
240+ # render outputs for a given season
231241render_season_output <- function (season_name , input , output , full_cache_data ) {
232242
233243 render_variable_menu(season_name , output , full_cache_data )
@@ -243,20 +253,20 @@ render_season_output <- function(season_name, input, output, full_cache_data) {
243253 render_timeline_hover(season_name , input , output , full_cache_data )
244254
245255 render_map(season_name , input , output , full_cache_data )
246-
247256}
248257
249- # render page elements
250258server <- function (input , output ) {
251259
260+ # load 'full_cache_data' object from cache file
252261 load(' cache.RData' )
253262
263+ # render UI for all available seasons
254264 output $ page_content <- renderUI({
255-
256265 season_tabs <- lapply(names(full_cache_data ), render_season_ui )
257266 do.call(tabsetPanel , season_tabs )
258267 })
259268
269+ # render outputs for all available seasons
260270 lapply(names(full_cache_data ), render_season_output , input , output , full_cache_data )
261271}
262272
0 commit comments