Learn R Programming

shinyCohortBuilder

Move your cohortBuilder workflow to Shiny.

Installation

# CRAN version
install.packages("shinyCohortBuilder")

# Latest development version
remotes::install_github("https://github.com/r-world-devs/shinyCohortBuilder")

Overview

With shinyCohortBuilder you can use cohortBuilder features within your shiny application.

Configure Source and Cohort filters with cohortBuilder (set value/range to NA to select all the options / the whole range, and active = FALSE to collapse filter in GUI):

librarian_source <- set_source(as.tblist(librarian))
librarian_cohort <- cohort(
  librarian_source,
  filter(
    "discrete", id = "author", dataset = "books", 
    variable = "author", value = "Dan Brown", 
    active = FALSE
  ),
  filter(
    "range", id = "copies", dataset = "books", 
    variable = "copies", range = c(5, 10), 
    active = FALSE
  ),
  filter(
    "date_range", id = "registered", dataset = "borrowers", 
    variable = "registered", range = c(as.Date("2010-01-01"), Inf),
    active = FALSE
  )
)

And apply in your application with cb_ui and cb_server:

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      cb_ui("librarian")
    ),
    mainPanel()
  )
)

server <- function(input, output, session) {
  cb_server("librarian", librarian_cohort)
}

shinyApp(ui, server)

You may listen to cohort data changes with input[[<cohort-id>-data-updated]]:

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      cb_ui("librarian")
    ),
    mainPanel(
      verbatimTextOutput("cohort_data")
    )
  )
)

server <- function(input, output, session) {
  cb_server("librarian", librarian_cohort)
  
  output$cohort_data <- renderPrint({
    input[["librarian-data-updated"]]
    get_data(librarian_cohort)
  })
  
}

shinyApp(ui, server)

Or run filtering panel locally what just makes your work with cohortBuilder easier:

gui(librarian_cohort)

If you’re interested in more features of shinyCohortBuilder please visit the package website.

Acknowledgement

Special thanks to:

  • Kamil Wais for highlighting the need for the package and its relevance to real-world applications.
  • Adam Foryś for technical support, numerous suggestions for the current and future implementation of the package.
  • Paweł Kawski for indication of initial assumptions about the package based on real-world medical data.

Getting help

In a case you found any bugs, have feature request or general question please file an issue at the package Github. You may also contact the package author directly via email at krystian8207@gmail.com.

Copy Link

Version

Install

install.packages('shinyCohortBuilder')

Monthly Downloads

316

Version

0.4.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Krystian Igras

Last Published

February 25th, 2026

Functions in shinyCohortBuilder (0.4.0)

cb_ui

Include filtering panel in Shiny
rendering-custom-attrition

Method for generating custom attrition output
cb_changed

Track changes of cohort data in Shiny
rendering-filters

Render filtering panels for all the filters included in Cohort
shinyCohortBuilder-package

GUI layer for cohortBuilder package
source-gui-layer

Source compatibility methods.
trigger-action

Trigger filtering panel action
updating-data-statistics

Render source data related statistics
.cb_input

Create input controller insensitive to server updates
.sendOutput

Send output rendering
demo_app

Run demo application
filter-position

Create target filter position in UI panel
.save_observer

Save observer to user session
autofilter

Generate filters definition based on the Source data
.render_filter

Define filter related output in filtering panel
available-filters-choices

Generate available filters choices based on the Source data
gui-filter-layer

Return GUI layer methods for filter of specified type
rendering-step-attrition

Generate output of attrition plot
scb_chart_palette

Default color palette used for filter feedback plots
keep_na_input

Generate NA's filter selection GUI input
pre_post_stats

Generate structure of pre/post statistics
scb_icons

Default filtering panel icons
scb_labels

Default filtering panel labels
gui

Run filtering panel locally