-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
452 lines (343 loc) · 9.64 KB
/
index.qmd
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
---
title: "No-code data analysis and dashboards with the blockr ecosystem"
author: Nicolas Bennett
date: April 10, 2025
format:
revealjs:
progress: true
controls: false
transition: slide
---
# What is blockr about?
## Blocks! {transition="slide-in none-out"}
{fig-align="center"}
## Blocks! {transition="none"}
{fig-align="center"}
## Blocks! {transition="none-in slide-out"}
{fig-align="center"}
# Demo
## Analysis
How do different models of planes perform? What about Airbus vs. Boeing?
```{r}
#| include: false
library(dplyr)
library(ggplot2)
```
```{r}
#| echo: true
#| code-line-numbers: "1-4|6-9|11-15"
pln <- nycflights13::planes |>
filter(seats >= 150) |>
select(tailnum, manufacturer, model) |>
mutate(manufacturer = sub(" INDUSTRIE$", "", manufacturer))
dat <- nycflights13::flights |>
mutate(delay = -(arr_delay - dep_delay)) |>
select(tailnum, delay) |>
inner_join(pln, by = "tailnum")
dat <- dat |>
summarize(count = n(), .by = c(manufacturer, model)) |>
mutate(pos = rank(-count)) |>
filter(pos <= 10) |>
left_join(dat, by = c("manufacturer", "model"))
```
## Endpoints
::: columns
::: {.column width="50%"}
```{r}
#| echo: true
t.test(
delay ~ manufacturer,
data = dat
)
```
:::
::: {.column width="50%"}
```{r}
#| layout-ncol: 1
ggplot(dat, aes(delay, model)) +
geom_boxplot()
ggplot(dat, aes(delay, color = manufacturer)) +
geom_histogram()
```
:::
:::
## Interactive blockr dashboard
```{r}
#| eval: false
library(blockr.ui)
library(blockr.core)
library(blockr.dplyr)
library(blockr.ggplot)
run_demo_app(
blocks = c(
a1 = new_dataset_block("planes", "nycflights13", name = "Flights"),
a2 = new_filter_block("seats >= 150"),
a3 = new_select_block(c("tailnum", "manufacturer", "model")),
a4 = new_mutate_block(
list(manufacturer = "sub(\" INDUSTRIE$\", \"\", manufacturer)")
),
b1 = new_dataset_block("flights", "nycflights13", name = "Planes"),
b2 = new_mutate_block(list(delay = "-(arr_delay - dep_delay)")),
b3 = new_select_block(c("tailnum", "delay")),
c1 = new_join_block("inner", "tailnum"),
c2 = new_summarize_block(
list(count = "dplyr::n()"),
c("manufacturer", "model")
),
c3 = new_mutate_block(list(pos = "rank(-count)")),
c4 = new_filter_block("pos <= 10"),
c5 = new_join_block("left", c("manufacturer", "model")),
d1 = new_boxplot_block("delay", "model"),
d2 = new_histogram_block("delay", "manufacturer"),
d3 = new_ttest_block("delay", "manufacturer")
),
links = c(
a1a2 = new_link("a1", "a2"),
a2a3 = new_link("a2", "a3"),
a3a4 = new_link("a3", "a4"),
b1b2 = new_link("b1", "b2"),
b2b3 = new_link("b2", "b3"),
b3c1 = new_link("b3", "c1", "y"),
a4c1 = new_link("a4", "c1", "x"),
c1c2 = new_link("c1", "c2"),
c2c3 = new_link("c2", "c3"),
c3c4 = new_link("c3", "c4"),
c4c5 = new_link("c4", "c5", "x"),
c1c5 = new_link("c1", "c5", "y"),
c5d1 = new_link("c5", "d1"),
c5d2 = new_link("c5", "d2"),
c5d3 = new_link("c5", "d3")
),
stacks = list(
a = paste0("a", 1:4),
b = paste0("b", 1:3),
c = paste0("c", 1:5),
d = paste0("d", 1:3)
)
)
```

# Extensibility
## A framework?
- [blockr.core](https://github.com/cynkra/blockr.core) objects/tools for creating blocks/links/stacks and managing a board
- [blockr.ui](https://github.com/cynkra/blockr.ui) front end, extending the core functionality
- Block packages such as [blockr.dplyr](https://github.com/cynkra/blockr.dplyr)
We provide 2 APIs: one for adding blocks and one for customizing/extending the front end.
## Adding a new block (1/5) {transition="slide-in none-out"}
1. Specify a block constructor
```{r}
#| echo: true
#| code-line-numbers: "2|3-7|8-12|13"
new_lm_block <- function(response = character(), ...) {
new_block(
server = function(id, dat) {
moduleServer(
# ...
)
},
ui = function(id) {
tagList(
# ...
)
},
class = c("lm_block", "model_block"),
...
)
}
```
## Adding a new block (1/5) {transition="none-in slide-out"}
1. Specify a block constructor
```{r}
#| echo: true
#| code-line-numbers: "29-31|8-9|11-15|18-23|24"
new_lm_block <- function(response = character(), ...) {
new_block(
server = function(id, dat) {
moduleServer(
id,
function(input, output, session) {
resp <- reactiveVal(response)
observeEvent(input$resp, resp(input$resp))
cols <- reactive(colnames(dat()))
observeEvent(
cols(),
updateSelectInput(session, "resp", "Response", cols(), resp())
)
list(
expr = reactive(
bquote(
stats::lm(.(y) ~ ., data = dat),
list(y = as.name(resp()))
)
),
state = list(response = resp)
)
}
)
},
ui = function(id) {
selectInput(NS(id, "resp"), "Response", response, response)
},
class = c("lm_block", "model_block"),
...
)
}
```
## Adding a new block (2/5)
2. (Optionally) provide some generic implementations for display
```{r}
#| echo: true
block_ui.model_block <- function(id, x, ...) {
verbatimTextOutput(NS(id, "result"))
}
block_output.model_block <- function(x, result, session) {
renderPrint(result)
}
```
## Adding a new block (3/5)
3. (Optionally) preview the block in a standalone app
```{r, eval = FALSE}
#| echo: true
serve(new_lm_block(), dat = datasets::attitude)
```

## Adding a new block (4/5)
4. Register the block for use in a dashboard
```{r, eval = FALSE}
#| echo: true
register_block(
new_lm_block,
name = "LM block",
description = "Linear model block"
)
```
## Adding a new block (5/5)
Our current (WIP) block extension packages:
* [cynkra/blockr.dplyr](https://github.com/cynkra/blockr.dplyr)
* [cynkra/blockr.ai](https://github.com/cynkra/blockr.ai)
* [cynkra/blockr.io](https://github.com/cynkra/blockr.io)
* [cynkra/blockr.db](https://github.com/cynkra/blockr.db)
* [cynkra/blockr.gt](https://github.com/cynkra/blockr.gt)
* [cynkra/blockr.ggplot](https://github.com/cynkra/blockr.ggplot)
Your own?
## Extending the front-end (1/2)
A set of plugins (each a shiny module) can be user-supplied:
* `preserve_board`: Serialization/deserialization
* `manage_*`: Add/remove `blocks`, `links` and `stacks`
* `notify_user`: Handling of notifications
* `generate_code`: Code export
* `edit_*`: Per `block`/`stack` options
## Extending the front-end (2/2)
::: columns
::: {.column width="50%"}
```r
serve(
new_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
::: {.column width="50%"}
```r
serve(
new_custom_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
:::
# Challenges
## Limitations of the shiny API
- Remove ([#2439](https://github.com/rstudio/shiny/issues/2439)) or reorder ([#4190](https://github.com/rstudio/shiny/issues/4190)) entries in a `reactiveValues` object: for variadic blocks (e.g. `rbind`) we need to be able to grow, shrink and reorder entries.
- Cleanup of dynamically created modules ([#2281](https://github.com/rstudio/shiny/issues/2281)): blocks (and stacks) are represented by modules which are dynamically added and removed.
In both cases we were able to come up with solutions (that circumvent the public API).
# Outro
## A collaborative effort
Joint work with David Granjon ([cynkra GmbH](https://cynkra.com)),
with contributions by John Coene ([The Y Company](https://the-y-company.com)), Karma Tarap ([Bristol-Myers Squibb](https://www.bms.com)) and Christoph Sax ([cynkra GmbH](https://cynkra.com)),
funded by [Bristol-Myers Squibb](https://www.bms.com).
## Further materials
- Prototype repo [BristolMyersSquibb/blockr](https://github.com/BristolMyersSquibb/blockr)
- Talk by David at useR 2024 in Salzburg ([slides](https://bristolmyerssquibb.github.io/useR2024))
- Workshop at "R in Pharma" ([Video](https://www.youtube.com/watch?v=PQvTQqcmadY))
- Discussion of prototype shortcomings and UI [wire-framing](https://excalidraw.com/#json=qYnQEvkzPgunMbErr4ulx,2c4c1kA16rY1Owhg54gPsQ)
- Re-write repo [cynkra/blockr.core](https://github.com/cynkra/blockr.core) with front-end package [cynkra/blockr.ui](https://github.com/cynkra/blockr.ui)
# Thanks for having me!
# Backup
## Interactive blockr dashboard {transition="slide-in none-out"}

## Interactive blockr dashboard {transition="none-in slide-out"}

## Extending the front-end (2/2) {transition="slide-in none-out"}
::: columns
::: {.column width="50%"}
```r
serve(
new_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
::: {.column width="50%"}
```r
serve(
new_custom_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
:::
## Extending the front-end (2/2) {transition="none"}
::: columns
::: {.column width="50%"}
```r
serve(
new_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
::: {.column width="50%"}
```r
serve(
new_custom_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
:::
## Extending the front-end (2/2) {transition="none-in slide-out"}
::: columns
::: {.column width="50%"}
```r
serve(
new_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
::: {.column width="50%"}
```r
serve(
new_custom_board(
c(a = new_dataset_block("mtcars"))
)
)
```

:::
:::