The DataframeFilteredDataset R6 class
Source: R/FilteredDatasetDataframe.R
DataframeFilteredDataset.RdThe DataframeFilteredDataset R6 class
The DataframeFilteredDataset R6 class
Super class
teal.slice::FilteredDataset -> DataframeFilteredDataset
Methods
Inherited methods
teal.slice::FilteredDataset$clear_filter_states()teal.slice::FilteredDataset$finalize()teal.slice::FilteredDataset$format()teal.slice::FilteredDataset$get_dataname()teal.slice::FilteredDataset$get_dataset()teal.slice::FilteredDataset$get_dataset_label()teal.slice::FilteredDataset$get_filter_state()teal.slice::FilteredDataset$get_keys()teal.slice::FilteredDataset$print()teal.slice::FilteredDataset$srv_active()teal.slice::FilteredDataset$srv_add()teal.slice::FilteredDataset$ui_active()
Method new()
Initializes this DataframeFilteredDataset object.
Usage
DataframeFilteredDataset$new(
dataset,
dataname,
keys = character(0),
parent_name = character(0),
parent = NULL,
join_keys = character(0),
label = character(0)
)Arguments
dataset(
data.frame) singledata.framefor which filters are rendered.dataname(
character(1)) syntactically valid name given to the dataset.keys(
character) optional vector of primary key column names.parent_name(
character(1)) name of the parent dataset.parent(
reactive) that returns a filtereddata.framefrom otherFilteredDatasetnamedparent_name. Passingparentresults in areactivelink that causes re-filtering of thisdatasetbased on the changes inparent.join_keys(
character) vector of names of columns in this dataset to join withparentdataset. If column names in the parent do not match these, they should be given as the names of this vector.label(
character(1)) label to describe the dataset.
Method get_call()
Gets the subset expression.
This function returns subset expressions equivalent to selected items
within each of filter_states. Configuration of the expressions 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 apply to one argument (...) in a dplyr::filter call.
Method set_filter_state()
Set filter state.
Method remove_filter_state()
Remove one or more FilterState form a FilteredDataset.
Method get_filter_overview()
Creates row for filter overview in the form of dataname -- observations (remaining/total) - data.frame
Examples
# use non-exported function from teal.slice
DataframeFilteredDataset <- getFromNamespace("DataframeFilteredDataset", "teal.slice")
library(shiny)
ds <- DataframeFilteredDataset$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))
#>
## set_filter_state
dataset <- DataframeFilteredDataset$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)
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
#> }
#> }