Skip to content

Commit

Permalink
Fix examples on decorator vignette (#1423)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin <[email protected]>
Fixes comments on vignette example on #1357
  • Loading branch information
llrs-roche authored Nov 22, 2024
1 parent 347b82a commit 0a15929
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions vignettes/decorate-module-output.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ if (interactive()) {

### Example Module

It is possible to pass any number of decorators (n) to a module. The example below demonstrates how to handle a dynamic number of decorators, allowing the user to choose which decorator to apply from a list. This makes the module more flexible and capable of accommodating various customization requirements.
It is possible to pass any number of decorators (n) to a module.
The example below demonstrates how to handle a dynamic number of decorators, allowing the user to choose which decorator to apply from a list.
This makes the module more flexible and capable of accommodating various customization requirements.

```{r}
library(ggplot2)
Expand Down Expand Up @@ -418,6 +420,11 @@ tm_decorated_plot <- function(label = "module", decorators = NULL) {
}
```

By order of the decorator we will:

1. Change the x axis title
2. Change the y axis title
3. Replace the x axis title

```{r}
interactive_decorator_1 <- teal_transform_module(
Expand Down Expand Up @@ -447,7 +454,7 @@ interactive_decorator_2 <- teal_transform_module(
ui = function(id) {
ns <- NS(id)
div(
textInput(ns("x_axis_title"), "X axis title", value = "x axis 2")
textInput(ns("y_axis_title"), "Y axis title", value = "y axis 1")
)
},
server = function(id, data) {
Expand All @@ -457,9 +464,9 @@ interactive_decorator_2 <- teal_transform_module(
within(data(),
{
plot <- plot +
xlab(title)
ylab(title)
},
title = input$x_axis_title
title = input$y_axis_title
)
})
})
Expand Down Expand Up @@ -492,6 +499,8 @@ interactive_decorator_3 <- teal_transform_module(

### Application

As you might have noted, the x axis title from the first decorator will be used but won't show up on the resulting plot:

```{r}
app <- init(
data = teal_data(iris = iris, mtcars = mtcars),
Expand Down

0 comments on commit 0a15929

Please sign in to comment.