alexdum commited on
Commit
20ff19a
·
1 Parent(s): dfb98ef

and set a 3-year default date range for monthly data in the UI.

Browse files
Files changed (2) hide show
  1. funs/plot_weather_jma.R +2 -0
  2. server.R +9 -1
funs/plot_weather_jma.R CHANGED
@@ -377,6 +377,8 @@ create_sunshine_plot_jma <- function(df, resolution = NULL) {
377
 
378
  date_range_str <- paste(format(min(df$DateTime), "%d %b %Y"), "-", format(max(df$DateTime), "%d %b %Y"))
379
  unit <- if (col == "Sunshine_Hours") "hours" else "min"
 
 
380
 
381
  plotly::plot_ly(data = df, x = ~DateTime, y = as.formula(paste0("~", col)), type = "bar",
382
  name = "Sunshine",
 
377
 
378
  date_range_str <- paste(format(min(df$DateTime), "%d %b %Y"), "-", format(max(df$DateTime), "%d %b %Y"))
379
  unit <- if (col == "Sunshine_Hours") "hours" else "min"
380
+
381
+
382
 
383
  plotly::plot_ly(data = df, x = ~DateTime, y = as.formula(paste0("~", col)), type = "bar",
384
  name = "Sunshine",
server.R CHANGED
@@ -303,7 +303,15 @@ server <- function(input, output, session) {
303
  end <- as.Date(input$filter_dates[2])
304
 
305
  # When changing resolution, usually we want to keep the End date and adjust Start if needed
306
- res <- check_and_limit_dates(start, end, input$filter_res, anchor = "end")
 
 
 
 
 
 
 
 
307
 
308
  if (res$limited) {
309
  updateDateRangeInput(session, "filter_dates", start = res$start, end = res$end)
 
303
  end <- as.Date(input$filter_dates[2])
304
 
305
  # When changing resolution, usually we want to keep the End date and adjust Start if needed
306
+ res_val <- input$filter_res
307
+
308
+ if (res_val == "Monthly") {
309
+ # Special rule for Monthly: Always default to 3 years back
310
+ new_start <- end - 365 * 3
311
+ res <- list(start = new_start, end = end, limited = TRUE, msg = "3 years")
312
+ } else {
313
+ res <- check_and_limit_dates(start, end, res_val, anchor = "end")
314
+ }
315
 
316
  if (res$limited) {
317
  updateDateRangeInput(session, "filter_dates", start = res$start, end = res$end)