Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix examples on decorator vignette #1423

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading