R/FilterPanelAPI.R
FilterPanelAPI.RdAn API class for managing filter states in a teal application's filter panel.
The purpose of this class is to encapsulate the API of the filter panel in a
new class FilterPanelAPI so that it can be passed and used in the server
call of any module instead of passing the whole FilteredData object.
This class is supported by methods to set, get, remove filter states in the filter panel API.
get_filter_state()Gets the reactive values from the active FilterState objects of the FilteredData object.
Gets all active filters in the form of a nested list.
The output list is a compatible input to set_filter_state.
set_filter_state()Sets active filter states.
remove_filter_state()Remove one or more FilterState of a FilteredDataset in the FilteredData object.
clear_filter_states()Remove all FilterStates of the FilteredData object.
library(shiny)
fd <- init_filtered_data(list(iris = iris))
fpa <- FilterPanelAPI$new(fd)
# get the actual filter state --> empty named list
isolate(fpa$get_filter_state())
#> {
#> "slices": [],
#> "attributes": {
#> "include_varnames" : {
#> "iris" : ["Sepal.Length", "Sepal.Width", ...
#> },
#> "count_type" : "none",
#> "allow_add" : true
#> }
#> }
# set a filter state
set_filter_state(
fpa,
teal_slices(
teal_slice(dataname = "iris", varname = "Species", selected = "setosa", keep_na = TRUE)
)
)
# get the actual filter state --> named list with filters
isolate(fpa$get_filter_state())
#> {
#> "slices": [
#> {
#> "dataname" : "iris",
#> "varname" : "Species",
#> "id" : "iris Species",
#> "choices" : ["setosa", "versicolor", "virgin...
#> "selected" : ["setosa"],
#> "keep_na" : true,
#> "fixed" : false,
#> "anchored" : false,
#> "multiple" : true
#> }
#> ],
#> "attributes": {
#> "include_varnames" : {
#> "iris" : ["Sepal.Length", "Sepal.Width", ...
#> },
#> "count_type" : "none",
#> "allow_add" : true
#> }
#> }
# remove all_filter_states
fpa$clear_filter_states()
# get the actual filter state --> empty named list
isolate(fpa$get_filter_state())
#> {
#> "slices": [],
#> "attributes": {
#> "include_varnames" : {
#> "iris" : ["Sepal.Length", "Sepal.Width", ...
#> },
#> "count_type" : "none",
#> "allow_add" : true
#> }
#> }