Render filtering panels for all the filters included in Cohort
Source:R/renders.R
, R/source_tblist.R
rendering-filters.Rd
The method exported only for custom extensions use.
Usage
.render_filters(source, ...)
# S3 method for default
.render_filters(source, cohort, step_id, ns, ...)
# S3 method for tblist
.render_filters(source, cohort, step_id, ns, ...)
Arguments
- source
Source object.
- ...
Extra arguments passed to a specific method.
- cohort
Cohort object.
- step_id
Id of the step.
- ns
Namespace function.
Details
Within the method you should define source data stats output (see .update_data_stats), and define a loop that renders filtering panel for each filter (using .render_filter).
Examples
if (interactive()) {
library(magrittr)
library(shiny)
library(cohortBuilder)
library(shinyCohortBuilder)
ui <- fluidPage(
actionButton("add_filter", "Add Filter"),
div(id = "filter_container")
)
server <- function(input, output, session) {
add_gui_filter_layer <- function(public, private, ...) {
private$steps[["1"]]$filters$copies$gui <- .gui_filter(
private$steps[["1"]]$filters$copies
)
private$steps[["1"]]$filters$registered$gui <- .gui_filter(
private$steps[["1"]]$filters$registered
)
}
add_hook("post_cohort_hook", add_gui_filter_layer)
coh <- cohort(
set_source(as.tblist(librarian)),
filter(
"range", id = "copies", name = "Copies", dataset = "books",
variable = "copies", range = c(5, 12)
),
filter(
"date_range", id = "registered", name = "Registered", dataset = "borrowers",
variable = "registered", range = c(as.Date("2010-01-01"), Inf)
)
) %>% run()
coh$attributes$session <- session
coh$attributes$feedback <- TRUE
observeEvent(input$add_filter, {
insertUI(
"#filter_container",
ui = .render_filters(
coh$get_source(),
cohort = coh,
step_id = "1",
ns = function(x) x
))
}, ignoreInit = TRUE, once = TRUE)
}
shinyApp(ui, server)
}