diff --git a/R/mod_datatable_filters.R b/R/mod_datatable_filters.R index c9c1485..c8a9084 100644 --- a/R/mod_datatable_filters.R +++ b/R/mod_datatable_filters.R @@ -49,6 +49,8 @@ mod_datatable_filters_ui <- function(id, #' #' @returns a filtered dataframe #' +#' @importFrom lubridate %m+% +#' @importFrom lubridate %m-% #' @export mod_datatable_filters_server <- function(id, @@ -61,8 +63,8 @@ mod_datatable_filters_server <- function(id, choices <- list( contributor_choices = reactiveVal(), dataset_choices = reactiveVal(), - release_daterange_start = reactiveVal(), - release_daterange_end = reactiveVal(), + release_daterange_min = reactiveVal(), + release_daterange_max = reactiveVal(), status_choices = reactiveVal() ) @@ -74,16 +76,25 @@ mod_datatable_filters_server <- function(id, is_all_na <- all(is.na(manifest()$scheduled_release_date)) if (is_all_na) { - choices$release_daterange_start(NA) - choices$release_daterange_end(NA) + choices$release_daterange_min(NULL) + choices$release_daterange_max(NULL) + print("ALL NA") } else { - choices$release_daterange_start(max(manifest()$scheduled_release_date, na.rm = T)) - choices$release_daterange_end(min(manifest()$scheduled_release_date, na.rm = T)) + + min_date <- min(manifest()$scheduled_release_date, na.rm = T) %m-% months(1) + max_date <- max(manifest()$scheduled_release_date, na.rm = T) %m+% months(1) + + choices$release_daterange_min(min_date) + choices$release_daterange_max(max_date) } }) # RENDER WIDGETS -------- output$filter_widgets <- shiny::renderUI({ + + print(paste0("min date - ", choices$release_daterange_min())) + print(paste0("max date - ", choices$release_daterange_max())) + tagList( shiny::selectInput(ns("contributor_select"), label = "Filter by contributor(s)", @@ -100,7 +111,9 @@ mod_datatable_filters_server <- function(id, shiny::dateRangeInput(ns("scheduled_release_daterange"), label = "Filter by scheduled release date", start = NA, - end = NA + end = NA, + min = choices$release_daterange_min(), + max = choices$release_daterange_max() ), shiny::selectInput(ns("status_select"), label = "Filter by status", @@ -143,7 +156,8 @@ mod_datatable_filters_server <- function(id, status %modifiedIn% selected_statuses_modified() ) - if (all(!is.na(input$scheduled_release_daterange)) & all(!is.null(input$scheduled_release_daterange))) { + if (all(!is.na(input$scheduled_release_daterange)) & + all(!is.null(input$scheduled_release_daterange))) { filtered <- filtered %>% dplyr::filter( scheduled_release_date >= input$scheduled_release_daterange[1] &