Skip to contents

The DefaultFilteredDataset R6 class

The DefaultFilteredDataset R6 class

Super class

teal.slice::FilteredDataset -> DefaultFilteredDataset

Methods

Inherited methods


Method new()

Initializes this DefaultFilteredDataset object

Usage

DefaultFilteredDataset$new(
  dataset,
  dataname,
  keys = character(0),
  label = character(0),
  metadata = NULL
)

Arguments

dataset

(data.frame)
single data.frame for which filters are rendered

dataname

(character)
A given name for the dataset it may not contain spaces

keys

optional, (character)
Vector with primary keys

label

(character)
Label to describe the dataset

metadata

(named list or NULL)
Field containing metadata about the dataset. Each element of the list should be atomic and length one.


Method get_call()

Gets the filter expression

This functions returns filter calls equivalent to selected items within each of filter_states. Configuration of the calls is constant and depends on filter_states type and order which are set during initialization. This class contains single FilterStates which contains single ReactiveQueue and all FilterState objects applies to one argument (...) in dplyr::filter call.

Usage

DefaultFilteredDataset$get_call()

Returns

filter call or list of filter calls


Method get_filter_state()

Gets the reactive values from the active FilterState objects.

Get all active filters from this dataset in form of the nested list. The output list is a compatible input to self$set_filter_state.

Usage

DefaultFilteredDataset$get_filter_state()

Returns

list with named elements corresponding to FilterState objects (active filters).


Method set_filter_state()

Set filter state

Usage

DefaultFilteredDataset$set_filter_state(state, ...)

Arguments

state

(named list)
containing values of the initial filter. Values should be relevant to the referred column.

...

Additional arguments. Note that this is currently not used

Returns

NULL

Examples

dataset <- teal.slice:::DefaultFilteredDataset$new(iris, "iris")
fs <- list(
  Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = TRUE),
  Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE)
)
dataset$set_filter_state(state = fs)
shiny::isolate(dataset$get_filter_state())


Method remove_filter_state()

Remove one or more FilterState of a FilteredDataset

Usage

DefaultFilteredDataset$remove_filter_state(element_id)

Arguments

element_id

(character)
Vector of character names of variables to remove their FilterState.

Returns

NULL


Method ui_add_filter_state()

UI module to add filter variable for this dataset

UI module to add filter variable for this dataset

Usage

DefaultFilteredDataset$ui_add_filter_state(id)

Arguments

id

(character(1))
identifier of the element - preferably containing dataset name

Returns

function - shiny UI module


Method srv_add_filter_state()

Server module to add filter variable for this dataset

Server module to add filter variable for this dataset. For this class srv_add_filter_state calls single module srv_add_filter_state from FilterStates (DefaultFilteredDataset contains single FilterStates)

Usage

DefaultFilteredDataset$srv_add_filter_state(id, ...)

Arguments

id

(character(1))
an ID string that corresponds with the ID used to call the module's UI function.

...

other arguments passed on to child FilterStates methods.

Returns

moduleServer function which returns NULL


Method get_filter_overview_nsubjs()

Get number of observations based on given keys The output shows the comparison between filtered_dataset function parameter and the dataset inside self

Usage

DefaultFilteredDataset$get_filter_overview_nsubjs(
  filtered_dataset = self$get_dataset(),
  subject_keys = NULL
)

Arguments

filtered_dataset

comparison object, of the same class as self$get_dataset(), if NULL then self$get_dataset() is used.

subject_keys

(character or NULL) columns denoting unique subjects when calculating the filtering.

Returns

list containing character #filtered/#not_filtered


Method clone()

The objects of this class are cloneable with this method.

Usage

DefaultFilteredDataset$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(shiny)
ds <- teal.slice:::DefaultFilteredDataset$new(iris, "iris")
ds$set_filter_state(
  state = list(
    Species = list(selected = "virginica"),
    Petal.Length = list(selected = c(2.0, 5))
  )
)
#> NULL
isolate(ds$get_filter_state())
#> $Species
#> $Species$selected
#> [1] "virginica"
#> 
#> $Species$keep_na
#> [1] FALSE
#> 
#> 
#> $Petal.Length
#> $Petal.Length$selected
#> [1] 2 5
#> 
#> $Petal.Length$keep_na
#> [1] FALSE
#> 
#> $Petal.Length$keep_inf
#> [1] FALSE
#> 
#> 
isolate(ds$get_call())
#> $filter
#> iris_FILTERED <- dplyr::filter(iris, Species == "virginica" & 
#>     (Petal.Length >= 2 & Petal.Length <= 5))
#> 

## ------------------------------------------------
## Method `DefaultFilteredDataset$set_filter_state`
## ------------------------------------------------

dataset <- teal.slice:::DefaultFilteredDataset$new(iris, "iris")
fs <- list(
  Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = TRUE),
  Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE)
)
dataset$set_filter_state(state = fs)
#> NULL
shiny::isolate(dataset$get_filter_state())
#> $Sepal.Length
#> $Sepal.Length$selected
#> [1] 5.1 6.4
#> 
#> $Sepal.Length$keep_na
#> [1] TRUE
#> 
#> $Sepal.Length$keep_inf
#> [1] TRUE
#> 
#> 
#> $Species
#> $Species$selected
#> [1] "setosa"     "versicolor"
#> 
#> $Species$keep_na
#> [1] FALSE
#> 
#>