Skip to content

Commit

Permalink
only allow date selections within min and max dates present in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
lakikowolfe committed Dec 6, 2023
1 parent 8c6336c commit d8c14c8
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions R/mod_datatable_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
)

Expand All @@ -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)",
Expand All @@ -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",
Expand Down Expand Up @@ -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] &
Expand Down

0 comments on commit d8c14c8

Please sign in to comment.