FilterStateExpr | R Documentation |
FilterStateExpr
R6
classSister class to FilterState
that handles arbitrary filter expressions.
Creates a filter state around a predefined condition call (logical predicate). The condition call is independent of the data and the filter card allows no interaction (the filter is always fixed).
new()
Initialize a FilterStateExpr
object.
FilterStateExpr$new(slice)
slice
(teal_slice_expr
)
Object of class FilterStateExpr
, invisibly.
format()
Returns a formatted string representing this FilterStateExpr
object.
FilterStateExpr$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 FilterStateExpr
object.
FilterStateExpr$print(...)
...
arguments passed to the format
method
NULL
, invisibly.
get_state()
Returns a complete description of this filter state.
FilterStateExpr$get_state()
A teal_slice
object.
set_state()
Does nothing. Exists for compatibility.
FilterStateExpr$set_state(state)
state
(teal_slice
)
self
, invisibly.
get_call()
Get reproducible call.
FilterStateExpr$get_call(dataname)
dataname
(ignored
) for a consistency with FilterState
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.
call
or NULL
destroy_observers()
Destroy observers stored in private$observers
.
FilterStateExpr$destroy_observers()
NULL
, invisibly.
server()
shiny
module server.
FilterStateExpr$server(id)
id
(character(1)
)
shiny
module instance id.
Reactive expression signaling that the remove button has been clicked.
ui()
shiny
module UI.
The UI for this class contains simple message stating that it is not supported.
FilterStateExpr$ui(id, parent_id = "cards")
id
(character(1)
)
shiny
module instance id.
parent_id
(character(1)
)
id of the FilterStates
card container.
clone()
The objects of this class are cloneable with this method.
FilterStateExpr$clone(deep = FALSE)
deep
Whether to make a deep clone.
# use non-exported function from teal.slice
include_js_files <- getFromNamespace("include_js_files", "teal.slice")
include_css_files <- getFromNamespace("include_css_files", "teal.slice")
FilterStateExpr <- getFromNamespace("FilterStateExpr", "teal.slice")
filter_state <- FilterStateExpr$new(
slice = teal_slice(
dataname = "x",
id = "FA",
title = "Adult females",
expr = "sex == 'F' & age >= 18"
)
)
filter_state$get_call()
# working filter in an app
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
include_css_files(pattern = "filter-panel"),
include_js_files(pattern = "count-bar-labels"),
column(4, tags$div(
tags$h4("ChoicesFilterState"),
filter_state$ui("fs")
)),
column(8, tags$div(
tags$h4("Condition (i.e. call)"), # display the condition call generated by this FilterState
textOutput("condition_choices"), tags$br(),
tags$h4("Unformatted state"), # display raw filter state
textOutput("unformatted_choices"), tags$br(),
tags$h4("Formatted state"), # display human readable filter state
textOutput("formatted_choices"), tags$br()
))
)
server <- function(input, output, session) {
filter_state$server("fs")
output$condition_choices <- renderPrint(filter_state$get_call())
output$formatted_choices <- renderText(filter_state$format())
output$unformatted_choices <- renderPrint(filter_state$get_state())
}
if (interactive()) {
shinyApp(ui, server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.