FilterState | R Documentation |
FilterState
abstract classAbstract class to encapsulate single filter state.
This class is responsible for managing a single filter item within a FilteredData
object
and outputs a condition call (logical predicate) for subsetting one variable.
Filter states depend on the variable type:
(logical
, integer
, numeric
, character
, factor
, Date
, POSIXct
, POSIXlt
)
and FilterState
subclasses exist that correspond to those types.
logical
: class = LogicalFilterState
integer
: class = RangeFilterState
numeric
: class = RangeFilterState
character
: class = ChoicesFilterState
factor
: class = ChoicesFilterState
Date
: class = DateFilterState
POSIXct
, POSIXlt
: class = DatetimeFilterState
all NA
entries: class: FilterState
, cannot be filtered
default: FilterState
, cannot be filtered
Each variable's filter state is an R6
object keeps the variable that is filtered,
a teal_slice
object that describes the filter state, as well as a shiny
module (UI and server)
that allows the user to alter the filter state.
Changes to the filter state that cause some observations to be omitted
trigger the get_call
method and every R
function call up in the reactive chain.
Modifying a FilterState
object is possible in three scenarios:
In an interactive session, by passing an appropriate teal_slice
to the set_state
method.
In a running application, by changing appropriate inputs.
In a running application, by using filter_state_api which directly uses
set_state
method of the FilterState
object.
new()
Initialize a FilterState
object.
FilterState$new( x, x_reactive = reactive(NULL), slice, extract_type = character(0) )
x
(vector
)
variable to be filtered.
x_reactive
(reactive
)
returning vector of the same type as x
. Is used to update
counts following the change in values of the filtered dataset.
If it is set to reactive(NULL)
then counts based on filtered
dataset are not shown.
slice
(teal_slice
)
specification of this filter state.
teal_slice
is stored in the object and set_state
directly manipulates values within teal_slice
.
get_state
returns teal_slice
object which can be reused in other places.
Note that teal_slice
is a reactiveValues
, which means it has reference semantics, i.e.
changes made to an object are automatically reflected in all places that refer to the same teal_slice
.
extract_type
(character
)
specifying whether condition calls should be prefixed by dataname
. Possible values:
character(0)
(default) varname
in the condition call will not be prefixed
"list"
varname
in the condition call will be returned as <dataname>$<varname>
"matrix"
varname
in the condition call will be returned as <dataname>[, <varname>]
Object of class FilterState
, invisibly.
format()
Returns a formatted string representing this FilterState
object.
FilterState$format(show_all = FALSE, trim_lines = TRUE)
show_all
(logical(1)
) passed to format.teal_slice
trim_lines
(logical(1)
) passed to format.teal_slice
character(1)
the formatted string
print()
Prints this FilterState
object.
FilterState$print(...)
...
additional arguments
set_state()
Sets mutable parameters of the filter state.
fixed
state is prevented from changing state
anchored
state is prevented from removing state
FilterState$set_state(state)
state
(teal_slice
)
self
invisibly
get_state()
Returns a complete description of the filter state.
FilterState$get_state()
A teal_slice
object.
get_call()
Returns reproducible condition call for current selection relevant for selected variable type. Method is using internal reactive values which makes it reactive and must be executed in reactive or isolated context.
FilterState$get_call()
server()
shiny
module server.
FilterState$server(id)
id
(character(1)
)
shiny
module instance id.
Reactive expression signaling that remove button has been clicked.
ui()
shiny
UI module.
The UI for this class contains simple message stating that it is not supported.
FilterState$ui(id, parent_id = "cards")
id
(character(1)
)
shiny
module instance id.
parent_id
(character(1)
) id of the FilterStates
card container
destroy_observers()
Destroy observers stored in private$observers
.
FilterState$destroy_observers()
NULL
, invisibly.
clone()
The objects of this class are cloneable with this method.
FilterState$clone(deep = FALSE)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.