@@ -11,11 +11,9 @@ source('render-site-map.R')
1111# schedule daily execution of cache refresh
1212cache_update_cmd <- cron_rscript(' cache-refresh.R' )
1313
14- if (! grepl(' cache-update' , cronR :: cron_ls())){
15- cron_add(command = cache_update_cmd , frequency = ' daily' ,
16- id = ' cache-update' , description = ' daily update of BETYdb cache' )
17- }
18-
14+ cron_clear(ask = FALSE )
15+ cron_add(command = cache_update_cmd , frequency = ' daily' ,
16+ id = ' cache-update' , description = ' daily update of BETYdb cache' )
1917
2018# set page UI
2119ui <- fluidPage(theme = shinytheme(' flatly' ),
@@ -103,31 +101,40 @@ render_trait_plot <- function(season_name, input, output, full_cache_data) {
103101 plot_data <- selected_season_data [[ ' trait_data' ]][[ selected_variable ]][[ ' traits' ]]
104102 data_max <- max(plot_data [[ ' mean' ]])
105103
106- title <- selected_variable
107104 units <- selected_season_data [[ ' trait_data' ]][[ selected_variable ]][[ ' units' ]]
108- if (units != ' ' )
109- title <- paste0(selected_variable , ' (' , units , ' )' )
110-
111- ggplot(plot_data , aes(as.Date(date ), mean )) +
112- geom_boxplot(aes(group = cut_width(as.Date(date ), 1 )), outlier.alpha = 0.1 ) +
113-
114- {
115- if (selected_cultivar != ' None' ) {
116- title <- paste0(title , ' for ' , selected_cultivar )
117- geom_line(data = subset(plot_data , cultivar_name == selected_cultivar ),
118- size = 0.5 , color = ' #00C49F' , aes(x = as.Date(date ), y = mean , group = site_id ))
119- }
120- } +
105+ title <- ifelse(units == ' ' , selected_variable , paste0(selected_variable , ' (' , units , ' )' ))
121106
122- labs(
123- title = paste0(title , ' \n ' ),
124- x = " Observation Dates" ,
125- y = units
126- ) +
107+ trait_plot <- ggplot() +
108+ geom_violin(data = plot_data , scale = ' width' , width = 1 ,
109+ aes(x = as.Date(date ), y = mean ,
110+ group = as.Date(date ))) +
111+ geom_boxplot(data = plot_data ,
112+ aes(x = as.Date(date ), y = mean ,
113+ group = as.Date(date )),
114+ outlier.alpha = 0.25 , width = 0.2 )
115+ # geom_point(data = plot_data,
116+ # aes(x = as.Date(date), y = mean),
117+ # alpha = 0.1, size = 0.1, position = position_jitter(width = 0.1))
118+
119+ if (selected_cultivar != ' None' ) {
120+ title <- paste0(title , ' \n Cultivar ' , selected_cultivar , ' in red' )
121+ trait_plot <- trait_plot +
122+ geom_point(data = subset(plot_data , cultivar_name == selected_cultivar ),
123+ color = ' red' , aes(x = as.Date(date ), y = mean , group = site_id )) +
124+ geom_line(data = subset(plot_data , cultivar_name == selected_cultivar ),
125+ size = 0.25 , color = ' red' , alpha = 0.25 , aes(x = as.Date(date ), y = mean , group = site_id ))
126+ }
127127
128- theme(text = element_text(size = 20 ), axis.text.x = element_text(angle = 45 , hjust = 1 ), legend.position = " none" ) +
129- xlim(as.Date(selected_season_data [[ ' start_date' ]]), as.Date(selected_season_data [[ ' end_date' ]])) +
130- ylim(0 , data_max )
128+ trait_plot +
129+ labs(
130+ title = paste0(title , ' \n ' ),
131+ x = " Date" ,
132+ y = units
133+ ) +
134+ theme_bw() +
135+ theme(text = element_text(size = 20 ), axis.text.x = element_text(angle = 45 , hjust = 1 ), legend.position = " none" ) +
136+ xlim(as.Date(selected_season_data [[ ' start_date' ]]), as.Date(selected_season_data [[ ' end_date' ]])) +
137+ ylim(0 , data_max )
131138 })
132139}
133140
@@ -192,8 +199,10 @@ render_timeline_hover <- function(season_name, input, output, full_cache_data) {
192199 selected_record <- management_data [ as.numeric(selected ), ]
193200
194201 formatted_notes <- ' '
195- if (selected_record [[ ' notes' ]] != ' ' )
202+ if (selected_record [[ ' notes' ]] != ' ' ) {
196203 formatted_notes <- paste0(' <br><br>' , selected_record [[ ' notes' ]])
204+ }
205+
197206
198207 wellPanel(class = ' mgmt-select-info' ,
199208 HTML(paste0(
@@ -228,12 +237,16 @@ render_map <- function(season_name, input, output, full_cache_data) {
228237
229238 traits <- full_cache_data [[ season_name ]][[ ' trait_data' ]][[ selected_variable ]][[ ' traits' ]]
230239
231- if (selected_cultivar != ' None' )
240+ if (selected_cultivar != ' None' ){
232241 traits <- subset(traits , cultivar_name == selected_cultivar )
242+ }
243+
233244
234245 units <- full_cache_data [[ season_name ]][[ ' trait_data' ]][[ selected_variable ]][[ ' units' ]]
235- if (units != ' ' )
246+ if (units != ' ' ) {
236247 units <- paste0(' (' , units , ' )' )
248+ }
249+
237250 legend_title <- paste0(selected_variable , ' ' , units )
238251
239252 render_site_map(traits , render_date , legend_title )
@@ -261,8 +274,10 @@ render_season_output <- function(season_name, input, output, full_cache_data) {
261274server <- function (input , output ) {
262275
263276 # load 'full_cache_data' object from cache file
264- if (! file.exists(' cache.RData' ))
277+ if (! file.exists(' cache.RData' )){
265278 source(' cache-refresh.R' )
279+ }
280+
266281 load(' cache.RData' )
267282
268283 # render UI for all available seasons
@@ -275,4 +290,4 @@ server <- function(input, output) {
275290 lapply(names(full_cache_data ), render_season_output , input , output , full_cache_data )
276291}
277292
278- shinyApp(ui = ui , server = server )
293+ shinyApp(ui = ui , server = server )
0 commit comments