Class to encapsulate the API of the filter panel of a teal app
FilterPanelAPI.RdClass to encapsulate the API of the filter panel of a teal app
Class to encapsulate the API of the filter panel of a teal app
Details
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.
Methods
Method 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.
Method set_filter_state()
Sets active filter states.
Method remove_filter_state()
Remove one or more FilterState of a FilteredDataset in the FilteredData object.
Method remove_all_filter_states()
Remove all FilterStates of the FilteredData object.
Examples
library(teal.slice)
fd <- teal.slice::init_filtered_data(list(iris = list(dataset = iris)))
fpa <- FilterPanelAPI$new(fd)
# get the actual filter state --> empty named list
isolate(fpa$get_filter_state())
#> named list()
#> attr(,"formatted")
#> [1] ""
# set a filter state
set_filter_state(fpa, list(iris = list(Species = list(selected = "setosa", keep_na = TRUE))))
# get the actual filter state --> named list with filters
isolate(fpa$get_filter_state())
#> $iris
#> $iris$Species
#> $iris$Species$selected
#> [1] "setosa"
#>
#> $iris$Species$keep_na
#> [1] TRUE
#>
#>
#>
#> attr(,"formatted")
#> [1] "Filters for dataset: iris\n Filtering on: Species\n Selected values: setosa\n Include missing values: TRUE"
# remove all_filter_states
fpa$remove_all_filter_states()
# get the actual filter state --> empty named list
isolate(fpa$get_filter_state())
#> named list()
#> attr(,"formatted")
#> [1] ""