# 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)
}
Run the code above in your browser using DataLab