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)
-}
+ 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)
+}