DataframeFilteredDataset R6 classR/FilteredDatasetDataframe.R
DataframeFilteredDataset.RdThe DataframeFilteredDataset R6 class
The DataframeFilteredDataset R6 class
teal.slice::FilteredDataset -> DataframeFilteredDataset
Inherited methods
teal.slice::FilteredDataset$clear_filter_states()teal.slice::FilteredDataset$destroy()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()
new()Initializes this DataframeFilteredDataset object.
DataframeFilteredDataset$new(
dataset,
dataname,
keys = character(0),
parent_name = character(0),
parent = NULL,
join_keys = character(0),
label = character(0)
)dataset(data.frame)
single data.frame for 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 filtered data.frame from other FilteredDataset named parent_name.
Passing parent results in a reactive link that causes re-filtering of this dataset
based on the changes in parent.
join_keys(character)
vector of names of columns in this dataset to join with parent dataset.
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.
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.
set_filter_state()Set filter state.
remove_filter_state()Remove one or more FilterState form a FilteredDataset.
get_filter_overview()Creates row for filter overview in the form of dataname -- observations (remaining/total) - data.frame
# 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
#> }
#> }