-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
154 lines (120 loc) · 4 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
output: github_document
---
```{r setup, include = FALSE}
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)
set.seed(123)
old_opts <- options()
options(tibble.width = Inf)
iris <- tibble::as.tibble(iris)
options("tibble.print_max" = 5)
options("tibble.print_min" = 5)
pkg_version <- read.dcf("DESCRIPTION", fields = "Version")[1, 1]
```
# shinyCohortBuilder <img src="man/figures/logo.png" align="right" width="120" />
Move your [cohortBuilder](https://r-world-devs.github.io/cohortBuilder/) workflow to Shiny.
![](man/figures/doc_01.gif)
[![version](https://img.shields.io/static/v1.svg?label=github.com&message=v.`r I(pkg_version)`&color=ff69b4)](https://r-world-devs.github.io/shinyCohortBuilder/)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
## Installation
```{r, eval = FALSE}
# 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):
```{r}
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`:
```{r, eval = FALSE}
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]]`:
```{r, eval = FALSE}
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:
```{r, eval = FALSE}
gui(librarian_cohort)
```
![](man/figures/01.png)
If you're interested in more features of `shinyCohortBuilder` please visit the package [website](https://r-world-devs.github.io/shinyCohortBuilder/).
## Acknowledgement
Special thanks to:
- [Kamil Wais](mailto:[email protected]) for highlighting the need for the package and its relevance to real-world applications.
- [Adam Foryś](mailto:[email protected]) for technical support, numerous suggestions for the current and future implementation of the package.
- [Paweł Kawski](mailto:[email protected]) 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](https://github.com/r-world-devs/shinyCohortBuilder/issues).
You may also contact the package author directly via email at [[email protected]](mailto:[email protected]).
```{r, include = FALSE}
options(old_opts)
```