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

pre-release vignettes review #681

Merged
merged 14 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
linters: linters_with_defaults(
line_length_linter = line_length_linter(120),
cyclocomp_linter = NULL,
object_usage_linter = NULL
object_usage_linter = NULL,
object_name_linter = object_name_linter(styles = c("snake_case", "symbols"), regexes = c(ANL = "^ANL_?[0-9]*$", ADaM = "^r?AD[A-Z]{2,3}_?[0-9]*$"))
)
2 changes: 0 additions & 2 deletions R/tm_g_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ srv_g_response <- function(id,
env = list(resp_var = resp_var)
)
) %>%
# nolint start
# rowf and colf will be a NULL if not set by a user
teal.code::eval_code(
substitute(
Expand All @@ -433,7 +432,6 @@ srv_g_response <- function(id,
env = list(x_cl = x_cl, rowf = rowf, colf = colf)
)
)
# nolint end

plot_call <- substitute(
expr = ggplot(ANL2, aes(x = x_cl, y = ns)) +
Expand Down
Binary file added vignettes/images/app-teal-modules-general.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-association-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-bivariate-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-cross-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-data-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-outliers-module.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-regression-plots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-response-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/images/app-using-scatterplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 47 additions & 52 deletions vignettes/teal-modules-general.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ vignette: >

### Introduction

`teal` is a package that extends the `shiny` framework to build interactive GUI applications using the R programming
language. `shiny`, and hence `teal`, are implemented to allow the building of large applications by combining small,
decoupled modules. `teal.modules.general` is a package consisting of a set of modules that are used to build `teal`
applications. It is "general" in the sense that the intended functions of these modules are more fundamental. This is
in contrast to the intended functions of its sister package, `teal.modules.clinical`, which is more specialized around
clinical data. The modules of `teal.modules.general` can be combined with modules of `teal.modules.clinical` and / or
`teal` extends the `shiny` framework, enabling the creation of interactive GUI applications using the `R`.
`shiny`, and `teal`facilitate the development of extensive applications through combining small, decoupled modules.
The `teal.modules.general` package consist of collection of modules essential for developing `teal` applications.
It is "general" in the sense that the intended functions of these modules are more fundamental. This contrasts with the more specialized focus on clinical data found in the `teal.modules.clinical` package.
The modules from `teal.modules.general` can be used in conjunction with modules from `teal.modules.clinical` and / or
other `shiny` modules to build a large `teal` / `shiny` app.


The concepts presented here require knowledge about the core features of `teal`, specifically on how to launch a `teal`
application and how to pass data into it. Therefore, it is highly recommended to refer to the [`README`](https://insightsengineering.github.io/teal/index.html) file and
the introductory [vignette](https://insightsengineering.github.io/teal/latest-tag/articles/teal.html) of the `teal` package.

See also `teal.modules.clinical's` [`README`](https://insightsengineering.github.io/teal.modules.clinical/latest-tag/index.html).
See also `teal.modules.clinical`'s [`README`](https://insightsengineering.github.io/teal.modules.clinical/latest-tag/index.html).

### Main features

There are five areas of data science that `teal.modules.general` provides tools and solutions (modules) for:

- viewing data in tabular form
- viewing data in tabular formats
- visualizing data in plots and graphs
- viewing data and files in a directory
- examining missing and extreme values in data
Expand All @@ -38,11 +38,13 @@ See [package functions / modules](https://insightsengineering.github.io/teal.mod

### Example application

A simple application including a `tm_variable_browser` module could look like this:
A simple application featuring the `tm_variable_browser()` module:
```{r, message = FALSE, results = "hide"}
# load libraries
library(teal.modules.general)
library(teal.widgets)

# nolint start
# teal_data object
data <- teal_data()
data <- within(data, {
ADSL <- teal.modules.general::rADSL
Expand All @@ -51,40 +53,42 @@ data <- within(data, {
datanames <- c("ADSL", "ADTTE")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
# nolint end

app <- teal::init(
data = data,
modules = teal::modules(
tm_variable_browser(
label = "Variable browser",
ggplot2_args = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot generated by Variable Browser Module")
),
)
# tm_variable_browser module
tm_variable_browser_module <- tm_variable_browser(
label = "Variable browser",
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by Variable Browser Module")
)
)

# initialize the app
app <- init(
data = data,
modules = modules(tm_variable_browser_module)
)
```

```{r, eval = FALSE}
shinyApp(app$ui, app$server)
```

<img src="images/app-teal-modules-general.png" style = "display: block; margin: 0px; width: 100%"/>

Let's break the above app into pieces:

1: Load the necessary libraries and data.
```r
library(teal.modules.general)
library(teal.widgets)
```
The line mentioned above imports the library required for this example and loads data from within that library.
2: Construct a `teal_data` object containing that will serve as the source of data for the `teal` app. `teal_data` not only encapsulates the data for the app, but it also houses the code required to create the data to maintain reproducibility.

Now, we are building a `teal_data` object that will serve as the source of data for the teal app.
`teal_data` not only encapsulates the data for the app, but it also houses the code required to create the data to maintain reproducibility.
To do this, we create an empty `teal_data` object and evaluate code to produce the data within the `teal_data` object,
so both the code and data are stored together.
To do this, we create an empty `teal_data` object and evaluate code to produce the data within the `teal_data` object, so both the code and data are stored together.

Following this, we set the `datanames` and `join_keys`.

```r
# nolint start
data <- teal_data()
data <- within(data, {
ADSL <- teal.modules.general::rADSL
Expand All @@ -93,49 +97,40 @@ data <- within(data, {
datanames <- c("ADSL", "ADTTE")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
# nolint end
```

There is no need to load `teal` as `teal.modules.general` already depends on it.
3: Initialize a `teal` application with specified data and modules, in this case, the module: `tm_variable_browser`, datasets:`ADSL` and `ADTTE`.

In the next step, we use `teal` to create `shiny` `ui` and `server` functions so we can launch using `shiny`. The `data`
argument tells `teal` about the input data - the two datasets `ADSL` and `ADTTE` - and the `modules`
argument indicates the modules included in the application. Here, we include only one - `tm_variable_browser`.
`shiny::shinyApp()` use the `ui` and `server` component to initialize the `teal` app.

```{r, results = "hide"}
app <- teal::init(
data = data,
modules = teal::modules(
tm_variable_browser(
# module name to display in the GUI
label = "Variable browser",
# this argument takes a set of arguments to pass to ggplot2.
# the arguments must have the same names as its ggplot2 counterpart, e.g. `subtitle`
ggplot2_args = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot generated by Variable Browser Module")
),
)

```r
tm_variable_browser_module <- tm_variable_browser(
# module name to display in the GUI
label = "Variable browser",
# this argument takes a set of arguments to pass to ggplot2.
# the arguments must have the same names as its ggplot2 counterpart, e.g. `subtitle`
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by Variable Browser Module")
)
)
```

The `shiny` function `shinyApp` used the `ui` and `server` objects to initialize the `teal` app.
app <- init(
data = data,
modules = modules(tm_variable_browser_module)
)

```{r, eval = FALSE}
shiny::shinyApp(app$ui, app$server)
shinyApp(app$ui, app$server)
```

In a `teal` app, data and modules are decoupled. In the app above:

- The app developer specified the data and assigned it to the `data` argument.
- The app developer specified the module and assigned it to the `modules` argument.
- The `init` function took these arguments and returned a list, which can be demonstrated by running:
- The `init` function took these arguments and returned a list containing `ui` and `server` object, which can be demonstrated by running:

```{r, indent = " "}
class(app)
```
This list contains two R objects named `ui` and `server`.
```{r, indent = " "}
names(app)
```

Loading