Skip to contents

Class 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 new()

Initialize a FilterPanelAPI object

Usage

FilterPanelAPI$new(datasets)

Arguments

datasets

(FilteredData) object.


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.

Usage

FilterPanelAPI$get_filter_state()

Returns

list with named elements corresponding to FilteredDataset objects with active filters.


Method set_filter_state()

Sets active filter states.

Usage

FilterPanelAPI$set_filter_state(filter)

Arguments

filter

(named list)
nested list of filter selections applied to datasets.

Returns

NULL


Method remove_filter_state()

Remove one or more FilterState of a FilteredDataset in the FilteredData object.

Usage

FilterPanelAPI$remove_filter_state(filter)

Arguments

filter

(named list)
nested list of filter selections applied to datasets.

Returns

NULL


Method remove_all_filter_states()

Remove all FilterStates of the FilteredData object.

Usage

FilterPanelAPI$remove_all_filter_states(datanames)

Arguments

datanames

(character)
datanames to remove their FilterStates; omit to remove all FilterStates in the FilteredData object

Returns

NULL


Method filter_panel_toggle()

Toggle the state of the global Filter Panel button by running javascript code to click the toggle button with the filter_panel_active id suffix. The button id is prefixed with the Filter Panel shiny namespace. This button is observed in srv_filter_panel method that executes filter_panel_enable() or filter_panel_disable() method depending on the toggle state.

Usage

FilterPanelAPI$filter_panel_toggle()

Returns

NULL


Method clone()

The objects of this class are cloneable with this method.

Usage

FilterPanelAPI$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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
isolate(
  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] ""