View source: R/server_filters.R
keep_only_relevant_values | R Documentation |
Filters out only relevant values based on the provided filters
keep_only_relevant_values(lFilters, sVariable, dfFilters)
lFilters |
List of filters to be applied on the data. |
sVariable |
The variable for which relevant values are to be retrieved. |
dfFilters |
Dataframe with the possible filters and values for this dataset |
This function removes null elements from the filter list, transforms filter list into elements suitable for filtering, and retrieves relevant values from the data.
A list of relevant values for the specified variable.
dfFilters <- dplyr::tibble(
var1 = sample(c("A", "B", "C"), 100, replace = TRUE),
var2 = sample(c("D", "E", "F"), 100, replace = TRUE),
var3 = sample(c("G", "H", "I"), 100, replace = TRUE)
)
filters <- list("D;var2")
relevant_values <- keep_only_relevant_values(filters, "var1", dfFilters)
# Check if the relevant values are only from the rows where var2 is "D" or "E"
expected_values <- dfFilters$var1[dfFilters$var2 %in% c("D")] %>%
purrr::set_names(.) %>%
purrr::map(~paste0(.x, ";var1"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.