Skip to content

Commit

Permalink
add empty line, replace selected to vars, remove interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
donyunardi committed Nov 6, 2024
1 parent 2d17da4 commit 9051ca0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions vignettes/creating-custom-modules.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ my_plot <- hist(
border = "black"
)
```

This module will allow users to dynamically select datasets and variables to create histograms within a `teal` application.
We will cover best practices, including setting up dynamic inputs, structuring server logic, and using the `teal_data` object to ensure reactivity and reproducibility.

Expand All @@ -35,7 +36,7 @@ We will cover best practices, including setting up dynamic inputs, structuring s
When developing a custom `teal` module for visualizations, we will first identify the primary inputs that users will interact with:

* **Dataset Input** (`dataset`): Allows users to select which dataset to explore.
* **Variable Input** (`selected`): Allows users to choose a specific numeric variable from the chosen dataset, ensuring only appropriate columns are available for plotting.
* **Variable Input** (`vars`): Allows users to choose a specific numeric variable from the chosen dataset, ensuring only appropriate columns are available for plotting.

These inputs are dynamically populated based on the available datasets and variables in the `teal_data` object, which we will cover later.

Expand Down Expand Up @@ -100,18 +101,22 @@ This syntax triggers reactivity, ensuring that the data within `teal_data` stays
### Using `datanames()` to Access Dataset Names in `teal_data` object

The `teal_data` object can contain multiple datasets. To retrieve the names of these datasets, use the `datanames()` function:

```r
datanames(data())
```

This will return a character vector of the dataset names contained in `teal_data`.
You can then use these names to dynamically populate input controls, like a dataset selection drop-down.

### Accessing Specific Datasets with Double Brackets (`[[ ]])`

To access an individual dataset from `teal_data`, use double brackets (`[[ ]]`) along with the dataset name. This allows you to extract the specific dataset as a data frame:

```r
data()[[input$dataset]]
```

Here, `input$dataset` represents the name of the dataset selected by the user. This syntax is highly flexible because it dynamically references whichever dataset the user has chosen. You can further subset or manipulate this extracted data frame as needed.

### Setting Up Server Logic Using `teal_data` and Dynamic Variable Injection
Expand Down Expand Up @@ -232,9 +237,7 @@ app <- init(
)

# Run the app
if (interactive()) {
shiny::shinyApp(ui = app$ui, server = app$server)
}
shiny::shinyApp(ui = app$ui, server = app$server)
```

**Congratulations! You just created a custom teal module and used it in a teal app!**
Expand Down

0 comments on commit 9051ca0

Please sign in to comment.