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),
  parent_name = character(0),
  parent = NULL,
  join_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

parent_name

(character(1))
Name of the parent dataset

parent

(reactive)
object returned by this reactive is a filtered data.frame from other FilteredDataset named parent_name. Consequence of passing parent is a reactive link which causes causing re-filtering of this dataset based on the changes in parent.

join_keys

(character)
Name of the columns in this dataset to join with parent dataset. If the column names are different if both datasets then the names of the vector define the parent columns.

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 state_list and all FilterState objects applies to one argument (...) in dplyr::filter call.

Usage

DefaultFilteredDataset$get_call(sid = "")

Arguments

sid

(character)
when specified then method returns code containing filter conditions of FilterState objects which "sid" attribute is different than this sid argument.

Returns

filter call or list of filter calls


Method set_filter_state()

Set filter state

Usage

DefaultFilteredDataset$set_filter_state(state)

Arguments

state

(teal_slice) object

Returns

NULL invisibly

Examples

dataset <- teal.slice:::DefaultFilteredDataset$new(iris, "iris")
fs <- teal_slices(
  teal_slice(dataname = "iris", varname = "Species", selected = "virginica"),
  teal_slice(dataname = "iris", varname = "Petal.Length", selected = c(2.0, 5))
)
dataset$set_filter_state(state = fs)
shiny::isolate(dataset$get_filter_state())


Method remove_filter_state()

Remove one or more FilterState form a FilteredDataset

Usage

DefaultFilteredDataset$remove_filter_state(state)

Arguments

state

(teal_slices)
specifying FilterState objects to remove; teal_slices may contain only dataname and varname, other elements are ignored

Returns

NULL invisibly


Method ui_add()

UI module to add filter variable for this dataset

UI module to add filter variable for this dataset

Usage

DefaultFilteredDataset$ui_add(id)

Arguments

id

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

Returns

function - shiny UI module


Method get_filter_overview()

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

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(
  teal_slices(
    teal_slice(dataname = "iris", varname = "Species", selected = "virginica"),
    teal_slice(dataname = "iris", varname = "Petal.Length", selected = c(2.0, 5))
  )
)
isolate(ds$get_filter_state())
#> {
#>   "slices": [
#>     {
#>       "dataname"       : "iris",
#>       "varname"        : "Species",
#>       "id"             : "iris Species",
#>       "choices"        : ["setosa", "versicolor", "virgin...
#>       "selected"       : ["virginica"],
#>       "fixed"          : false,
#>       "anchored"       : false,
#>       "multiple"       : true
#>     },
#>     {
#>       "dataname"       : "iris",
#>       "varname"        : "Petal.Length",
#>       "id"             : "iris Petal.Length",
#>       "choices"        : [1, 6.9000000000000004],
#>       "selected"       : [2, 5],
#>       "fixed"          : false,
#>       "anchored"       : false,
#>       "multiple"       : true
#>     }
#>   ],
#>   "attributes": {
#>     "include_varnames" : {
#>       "iris"           : ["Sepal.Length", "Sepal.Width", ...
#>     },
#>     "count_type"       : "none",
#>     "allow_add"        : true
#>   }
#> } 
isolate(ds$get_call())
#> $filter
#> iris <- dplyr::filter(iris, Species == "virginica" & (Petal.Length >= 
#>     2 & Petal.Length <= 5))
#> 

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

dataset <- teal.slice:::DefaultFilteredDataset$new(iris, "iris")
fs <- teal_slices(
  teal_slice(dataname = "iris", varname = "Species", selected = "virginica"),
  teal_slice(dataname = "iris", varname = "Petal.Length", selected = c(2.0, 5))
)
dataset$set_filter_state(state = fs)
shiny::isolate(dataset$get_filter_state())
#> {
#>   "slices": [
#>     {
#>       "dataname"       : "iris",
#>       "varname"        : "Species",
#>       "id"             : "iris Species",
#>       "choices"        : ["setosa", "versicolor", "virgin...
#>       "selected"       : ["virginica"],
#>       "fixed"          : false,
#>       "anchored"       : false,
#>       "multiple"       : true
#>     },
#>     {
#>       "dataname"       : "iris",
#>       "varname"        : "Petal.Length",
#>       "id"             : "iris Petal.Length",
#>       "choices"        : [1, 6.9000000000000004],
#>       "selected"       : [2, 5],
#>       "fixed"          : false,
#>       "anchored"       : false,
#>       "multiple"       : true
#>     }
#>   ],
#>   "attributes": {
#>     "include_varnames" : {
#>       "iris"           : ["Sepal.Length", "Sepal.Width", ...
#>     },
#>     "count_type"       : "none",
#>     "allow_add"        : true
#>   }
#> }