knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = TRUE, echo = TRUE, message = TRUE, warning = TRUE, fig.width = 8, fig.height = 6, dpi = 200, fig.align = "center", fig.path = "man/figures/README-" ) library(magrittr) library(cohortBuilder) library(shinyCohortBuilder) library(cohortBuilder.db) set.seed(123) options(tibble.width = Inf) iris <- tibble::as.tibble(iris) options("tibble.print_max" = 5) options("tibble.print_min" = 5)
cohortBuilder.db is database layer for cohortBuilder and shinyCohortBuilder.
The package allows you to operate with cohortBuilder
API on remote tables stores within a database.
All of the operations are performed directly on the database server side!
# CRAN version install.packages("cohortBuilder.db") # Latest development version remotes::install_github("https://github.com/r-world-devs/cohortBuilder.db")
cohortBuilder.db
allows you to use cohortBuilder
and shinyCohortBuilder
features working with database connection.
Comparing to the standard workflow (working on list of tables) you just need to create database tables configuration using dbtables
where you provide database connection, schema name and table names.
Than pass the created object to set_source
method:
library(cohortBuilder) library(cohortBuilder.db) db_tables_conf <- dbtables( connection = <db-connection>, schema = <schema-name>, tables = <vector-of-table-names-to-use> ) librarian_db_source <- set_source( db_tables_conf )
and configure Cohort using the same rules known from cohortBuilder
:
librarian_db_cohort <- cohort( librarian_source, filter( "discrete", id = "author", dataset = "books", variable = "author", value = "Dan Brown" ), filter( "range", id = "copies", dataset = "books", variable = "copies", range = c(5, 10) ), filter( "date_range", id = "registered", dataset = "borrowers", variable = "registered", range = c(as.Date("2010-01-01"), Inf) ) )
Now feel free to use all the known cohortBuilder
features.
You can also use shinyCohortBuilder
to use cohortBuilder
features in shiny.
Just use db-based Cohort with the known approach:
library(shiny) library(shinyCohortBuilder) ui <- fluidPage( sidebarLayout( sidebarPanel( cb_ui("librarian") ), mainPanel( verbatimTextOutput("cohort_data") ) ) ) server <- function(input, output, session) { cb_server("librarian", librarian_db_cohort) output$cohort_data <- renderPrint({ input[["librarian-data-updated"]] get_data(librarian_cohort) }) } shinyApp(ui, server)
Special thanks to:
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.