Class to encapsulate the API of the filter panel of a teal app
Source:R/FilterPanelAPI.R
FilterPanelAPI.Rd
An API class for managing filter states in a teal application's filter panel.
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 clear_filter_states()
Remove all FilterStates
of the FilteredData
object.
Examples
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
#> }
#> }