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

Datanames in vignettes #1434

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export(modules)
export(new_tdata)
export(report_card_template)
export(reporter_previewer_module)
export(set_datanames)
export(show_rcode_modal)
export(srv_teal)
export(srv_teal_with_splash)
Expand Down
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Introduced `teal_transform_module` to provide a way to interactively modify data delivered to `teal_module`'s `server` and to decorate module outputs. #1228 #1384
* Introduced a new argument `once = FALSE` in `teal_data_module` to possibly reload data during a run time.
* Possibility to download lockfile to restore app session for reproducibility. #479
* Introduced a function `set_datanames()` to change a `datanames` of the `teal_module`.
* Datasets which name starts with `.` are ignored when `module`'s `datanames` is set as `"all"`.
* Added warning when reserved `datanames`, such as `all` and `.raw_data` are being used.

Expand Down
1 change: 0 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#'
#' @param data (`teal_data` or `teal_data_module`)
#' For constructing the data object, refer to [teal.data::teal_data()] and [teal_data_module()].
#' If `datanames` are not set for the `teal_data` object, defaults from the `teal_data` environment will be used.
#' @param modules (`list` or `teal_modules` or `teal_module`)
#' Nested list of `teal_modules` or `teal_module` objects or a single
#' `teal_modules` or `teal_module` object. These are the specific output modules which
Expand Down
41 changes: 3 additions & 38 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ setOldClass("teal_modules")
#' and the report previewer module [reporter_previewer_module()], respectively.
#'
#' # Restricting datasets used by `teal_module`:
#'
#' The `datanames` argument controls which datasets are used by the module’s server. These datasets,
#' passed via server's `data` argument, are the only ones shown in the module's tab.
#'
Expand All @@ -29,11 +30,8 @@ setOldClass("teal_modules")
#' - Proxy variables for column modifications
#' - Temporary datasets used to create final versions
#' - Connection objects
#'
#' To exclude irrelevant datasets, use the [set_datanames()] function to change `datanames` from
#' `"all"` to specific names. Trying to modify non-`"all"` values with [set_datanames()] will result
#' in a warning. Datasets with names starting with . are ignored globally unless explicitly listed
#' in `datanames`.
#' Datasets which name is prefixed in `teal_data` by the dot (`.`) are not displayed in the `teal` application.
#' Please see the _"Hidden datasets"_ section in `vignette("including-data-in-teal-applications").
#'
#' # `datanames` with `transformators`
#' When transformators are specified, their `datanames` are added to the module’s `datanames`, which
Expand Down Expand Up @@ -591,39 +589,6 @@ print.teal_modules <- function(x, ...) {
invisible(x)
}

#' @param modules (`teal_module` or `teal_modules`)
#' @rdname teal_modules
#' @examples
#' # change the module's datanames
#' set_datanames(module(datanames = "all"), "a")
#'
#' # change modules' datanames
#' set_datanames(
#' modules(
#' module(datanames = "all"),
#' module(datanames = "a")
#' ),
#' "b"
#' )
#' @export
set_datanames <- function(modules, datanames) {
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"))
if (inherits(modules, "teal_modules")) {
modules$children <- lapply(modules$children, set_datanames, datanames)
} else {
if (identical(modules$datanames, "all")) {
modules$datanames <- datanames
} else {
warning(
"Not possible to modify datanames of the module ", modules$label,
". set_datanames() can only change datanames if it was set to \"all\".",
call. = FALSE
)
}
}
modules
}

# utilities ----
## subset or modify modules ----

Expand Down
3 changes: 1 addition & 2 deletions man/init.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions man/teal_modules.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vignettes/creating-custom-modules.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ Let's review what we've done so far:
The `teal::module()` function allows you to encapsulate your UI and server logic into a `teal` module, making it reusable and ready to integrate into any `teal` application.

By setting `datanames = "all"`, you give the module access to all datasets specified in the `teal_data` object.
Datasets which names start with `.` won't be included (see [Hidden datasets](including-data-in-teal-applications.html#hidden-datasets) section).

```r
# Custom histogram module creation
Expand Down
22 changes: 22 additions & 0 deletions vignettes/including-data-in-teal-applications.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,28 @@ For a detailed explanation of verification, see [this `teal.data` vignette](http

<br>

##### Hidden datasets

An object is hidden in `teal_data` and `teal` application if its name starts with a dot (`.`). This can be used to pass auxiliary objects in the `teal_data` instance, without being visible in the `teal` summary and filter panel.

```{r}
my_data <- teal_data()
my_data <- within(my_data, {
.data1 <- data.frame(id = 1:10, x = 11:20)
.data2 <- data.frame(id = 1:10, y = 11:20)
data <- merge(.data1, .data2)
})

ls(my_data)
names(my_data)

app <- init(data = my_data, modules = example_module())

if (interactive()) {
shinyApp(app$ui, app$server)
}
```

## Further reading

For a complete guide to the `teal_data` class, please refer to the [`teal.data` package](https://insightsengineering.github.io/teal.data/latest-tag/).
Loading