@@ -61,6 +61,7 @@ We modify the title and x-axis label of plot:
61
61
``` {r}
62
62
library(teal)
63
63
static_decorator <- teal_transform_module(
64
+ label = "Static decorator",
64
65
server = function(id, data) {
65
66
moduleServer(id, function(input, output, session) {
66
67
reactive({
@@ -82,6 +83,7 @@ you can use the [`make_teal_transform_server()`](https://insightsengineering.git
82
83
83
84
``` {r}
84
85
static_decorator_lang <- teal_transform_module(
86
+ label = "Static decorator (language)",
85
87
server = make_teal_transform_server(
86
88
expression(
87
89
plot <- plot +
@@ -100,6 +102,7 @@ Note how the input parameters are passed to the [`within`](https://insightsengin
100
102
101
103
``` {r}
102
104
interactive_decorator <- teal_transform_module(
105
+ label = "Interactive decorator",
103
106
ui = function(id) {
104
107
ns <- NS(id)
105
108
div(
@@ -129,6 +132,7 @@ This wrapper requires you to use `input` object names directly in the expression
129
132
130
133
``` {r}
131
134
interactive_decorator_lang <- teal_transform_module(
135
+ label = "Interactive decorator (language)",
132
136
ui = function(id) {
133
137
ns <- NS(id)
134
138
div(
@@ -155,6 +159,7 @@ In the following example, focus on the `output_name` parameter to see how decora
155
159
``` {r}
156
160
gg_xlab_decorator <- function(output_name) {
157
161
teal_transform_module(
162
+ label = "X-axis decorator",
158
163
ui = function(id) {
159
164
ns <- NS(id)
160
165
div(
@@ -186,6 +191,7 @@ If a decorator fails, the outputs will not be shown, and an appropriate error me
186
191
187
192
``` {r}
188
193
failing_decorator <- teal_transform_module(
194
+ label = "Failing decorator",
189
195
ui = function(id) {
190
196
ns <- NS(id)
191
197
div(
@@ -194,7 +200,7 @@ failing_decorator <- teal_transform_module(
194
200
},
195
201
server = function(id, data) {
196
202
moduleServer(id, function(input, output, session) {
197
- reactive(stop("This is error"))
203
+ reactive(stop("\nThis is an error produced by decorator\n "))
198
204
})
199
205
}
200
206
)
@@ -357,8 +363,9 @@ tm_decorated_plot <- function(label = "module", decorators = NULL) {
357
363
updateSelectInput(inputId = "dataname", choices = names(data()))
358
364
})
359
365
360
- observeEvent(input$dataname, {
361
- req(input$dataname)
366
+ dataname <- reactive(req(input$dataname))
367
+
368
+ observeEvent(dataname(), {
362
369
updateSelectInput(inputId = "x", choices = colnames(data()[[input$dataname]]))
363
370
updateSelectInput(inputId = "y", choices = colnames(data()[[input$dataname]]))
364
371
})
@@ -374,7 +381,6 @@ tm_decorated_plot <- function(label = "module", decorators = NULL) {
374
381
})
375
382
})
376
383
377
- dataname <- reactive(req(input$dataname))
378
384
x <- reactive({
379
385
req(input$x, input$x %in% colnames(data()[[dataname()]]))
380
386
input$x
@@ -403,7 +409,7 @@ tm_decorated_plot <- function(label = "module", decorators = NULL) {
403
409
})
404
410
405
411
decorated_data_no_print <- srv_transform_teal_data(
406
- paste0 ("decorate_", selected_decorator()),
412
+ sprintf ("decorate_%s ", selected_decorator()),
407
413
data = plot_data,
408
414
transformators = decorators[[selected_decorator()]]
409
415
)
@@ -430,6 +436,7 @@ By order of the decorator we will:
430
436
431
437
``` {r}
432
438
interactive_decorator_1 <- teal_transform_module(
439
+ label = "Interactive decorator 1",
433
440
ui = function(id) {
434
441
ns <- NS(id)
435
442
div(
@@ -453,6 +460,7 @@ interactive_decorator_1 <- teal_transform_module(
453
460
)
454
461
455
462
interactive_decorator_2 <- teal_transform_module(
463
+ label = "Interactive decorator 2",
456
464
ui = function(id) {
457
465
ns <- NS(id)
458
466
div(
@@ -476,6 +484,7 @@ interactive_decorator_2 <- teal_transform_module(
476
484
)
477
485
478
486
interactive_decorator_3 <- teal_transform_module(
487
+ label = "Interactive decorator 3",
479
488
ui = function(id) {
480
489
ns <- NS(id)
481
490
div(
@@ -540,7 +549,7 @@ The following module generates both a scatter plot and a summary table. Each of
540
549
``` {r}
541
550
tm_decorated_plot_table <- function(label = "module with two outputs", decorators = list()) {
542
551
checkmate::assert_list(decorators, "teal_transform_module", null.ok = TRUE)
543
-
552
+
544
553
module(
545
554
label = label,
546
555
ui = function(id, decorators) {
@@ -562,13 +571,13 @@ tm_decorated_plot_table <- function(label = "module with two outputs", decorator
562
571
updateSelectInput(inputId = "dataname", choices = names(data()))
563
572
})
564
573
565
- observeEvent(input$dataname, {
566
- req(input$dataname)
574
+ dataname <- reactive(req(input$dataname))
575
+
576
+ observeEvent(dataname(), {
567
577
updateSelectInput(inputId = "x", choices = colnames(data()[[input$dataname]]))
568
578
updateSelectInput(inputId = "y", choices = colnames(data()[[input$dataname]]))
569
579
})
570
580
571
- dataname <- reactive(req(input$dataname))
572
581
x <- reactive({
573
582
req(input$x, input$x %in% colnames(data()[[dataname()]]))
574
583
input$x
@@ -597,11 +606,11 @@ tm_decorated_plot_table <- function(label = "module with two outputs", decorator
597
606
table_data <- reactive({
598
607
req(dataname())
599
608
within(data(),
600
- {
601
- table_data <- dataname %>%
602
- dplyr::summarise(dplyr::across(dplyr::everything(), mean, na.rm = TRUE))
603
- },
604
- dataname = as.name(dataname())
609
+ {
610
+ table_data <- dataname %>%
611
+ dplyr::summarise(dplyr::across(dplyr::everything(), mean, na.rm = TRUE))
612
+ },
613
+ dataname = as.name(dataname())
605
614
)
606
615
})
607
616
@@ -619,28 +628,21 @@ tm_decorated_plot_table <- function(label = "module with two outputs", decorator
619
628
transformators = decorators$table
620
629
)
621
630
622
- output$plot <- renderPlot({
623
- req(decorated_plot())
624
- decorated_plot()[["plot"]]
625
- })
631
+ output$plot <- renderPlot(decorated_plot()[["plot"]])
626
632
627
- output$table <- renderTable({
628
- req(decorated_table())
629
- decorated_table()[["table_data"]]
630
- })
633
+ output$table <- renderTable(decorated_table()[["table_data"]])
631
634
632
635
output$text <- renderText({
633
636
plot_code <- teal.code::get_code(req(decorated_plot()))
634
637
table_code <- teal.code::get_code(req(decorated_table()))
635
- paste("Plot Code:", plot_code, "\nTable Code:", table_code)
638
+ paste("# Plot Code:", plot_code, "\n\n# Table Code:", table_code)
636
639
})
637
640
})
638
641
},
639
642
ui_args = list(decorators = decorators),
640
643
server_args = list(decorators = decorators)
641
644
)
642
645
}
643
-
644
646
```
645
647
646
648
@@ -659,11 +661,10 @@ plot_decorator <- teal_transform_module(
659
661
reactive({
660
662
req(data())
661
663
within(data(),
662
- {
663
- plot <- plot +
664
- ggplot2::ggtitle(ptitle)
665
- },
666
- ptitle = input$plot_title
664
+ {
665
+ plot <- plot + ggplot2::ggtitle(ptitle)
666
+ },
667
+ ptitle = input$plot_title
667
668
)
668
669
})
669
670
})
@@ -676,13 +677,15 @@ plot_decorator <- teal_transform_module(
676
677
677
678
``` {r}
678
679
table_decorator <- teal_transform_module(
680
+ label = "Decorate plot",
679
681
server = make_teal_transform_server(
680
682
expression({
681
- rownames(table_data) <- paste0("Row ", seq_len(nrow(table_data)))
683
+ table_data$id <- paste0("Row ", seq_len(nrow(table_data)))
684
+ table_data <- table_data[, union("id", colnames(table_data))]
685
+ colnames(table_data)[1] <- "ID (decorated)"
682
686
})
683
687
)
684
688
)
685
-
686
689
```
687
690
688
691
@@ -705,5 +708,4 @@ app <- init(
705
708
if (interactive()) {
706
709
shinyApp(app$ui, app$server)
707
710
}
708
-
709
711
```
0 commit comments