Skip to content

Commit

Permalink
docs: update the vignettes to use the new teal_data object
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhav committed Nov 7, 2023
1 parent eb7a07e commit d09651f
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 482 deletions.
41 changes: 27 additions & 14 deletions vignettes/teal-modules-general.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ A simple application including a `tm_variable_browser` module could look like th
```{r, message = FALSE, results = "hide"}
library(teal.modules.general)
ADSL <- teal.modules.general::rADSL # nolint
ADTTE <- teal.modules.general::rADTTE # nolint
data <- teal_data()
data <- within(data, {
ADSL <- teal.modules.general::rADSL

Check warning on line 48 in vignettes/teal-modules-general.Rmd

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=vignettes/teal-modules-general.Rmd,line=48,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
ADTTE <- teal.modules.general::rADTTE

Check warning on line 49 in vignettes/teal-modules-general.Rmd

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=vignettes/teal-modules-general.Rmd,line=49,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
})
datanames <- c("ADSL", "ADTTE")
datanames(data) <- datanames
data@join_keys <- cdisc_join_keys(!!!datanames)
app <- teal::init(
data = teal.data::cdisc_data(
teal.data::cdisc_dataset("ADSL", x = ADSL, code = "ADSL <- teal.modules.general::rADSL"),
teal.data::cdisc_dataset("ADTTE", x = ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"),
check = TRUE
),
data = data,
modules = teal::modules(
tm_variable_browser(
label = "Variable browser",
Expand All @@ -72,10 +74,25 @@ Let's break the above app into pieces:
library(teal.modules.general)
```
The line mentioned above imports the library required for this example and loads data from within that library.

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.

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

```r
ADSL <- teal.modules.general::rADSL
ADAE <- teal.modules.general::rADAE
data <- teal_data()
data <- within(data, {
ADSL <- teal.modules.general::rADSL
ADTTE <- teal.modules.general::rADTTE
})
datanames <- c("ADSL", "ADTTE")
datanames(data) <- datanames
data@join_keys <- cdisc_join_keys(!!!datanames)
```

There is no need to load `teal` as `teal.modules.general` already depends on it.

In the next step, we use `teal` to create `shiny` `ui` and `server` functions so we can launch using `shiny`. The `data`
Expand All @@ -84,11 +101,7 @@ argument indicates the modules included in the application. Here, we include onl

```{r, results = "hide"}
app <- teal::init(
data = teal.data::cdisc_data(
teal.data::cdisc_dataset("ADSL", x = ADSL, code = "ADSL <- teal.modules.general::rADSL"),
teal.data::cdisc_dataset("ADTTE", x = ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"),
check = TRUE # to check if the code executes to the data provided, x, i.e. ADSL and ADTTE
),
data = data,
modules = teal::modules(
tm_variable_browser(
# module name to display in the GUI
Expand Down
98 changes: 48 additions & 50 deletions vignettes/using-association-plot.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,28 @@ itself will be constructed by multiple calls of `tm_g_association` using differe
combinations of data sets.

```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"}
data <- teal_data()
data <- within(data, {
ADSL <- teal.modules.general::rADSL

Check warning on line 66 in vignettes/using-association-plot.Rmd

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=vignettes/using-association-plot.Rmd,line=66,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
ADSL2 <- ADSL %>%

Check warning on line 67 in vignettes/using-association-plot.Rmd

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=vignettes/using-association-plot.Rmd,line=67,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))
ADRS <- teal.modules.general::rADRS

Check warning on line 69 in vignettes/using-association-plot.Rmd

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=vignettes/using-association-plot.Rmd,line=69,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
ADTTE <- teal.modules.general::rADTTE

Check warning on line 70 in vignettes/using-association-plot.Rmd

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=vignettes/using-association-plot.Rmd,line=70,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
ADLB <- teal.modules.general::rADLB %>%

Check warning on line 71 in vignettes/using-association-plot.Rmd

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=vignettes/using-association-plot.Rmd,line=71,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
mutate(CHGC = as.factor(case_when(
CHG < 1 ~ "N",
CHG > 1 ~ "P",
TRUE ~ "-"
)))
})
datanames <- c("ADSL", "ADSL2", "ADRS", "ADTTE", "ADLB")
datanames(data) <- datanames
data@join_keys <- cdisc_join_keys(!!!datanames)
data@join_keys$mutate(
"ADSL2", "ADSL", get_cdisc_keys("ADSL")
)
app <- teal::init(
data = teal.data::cdisc_data(
teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"),
teal.data::cdisc_dataset(
"ADSL2",
ADSL2,
keys = get_cdisc_keys("ADSL"),
code = "ADSL2 <- teal.modules.general::rADSL %>%
mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))"
),
teal.data::cdisc_dataset("ADRS", ADRS, code = "ADRS <- teal.modules.general::rADRS"),
teal.data::cdisc_dataset("ADTTE", ADTTE, code = "ADTTE <- teal.modules.general::rADTTE"),
teal.data::cdisc_dataset(
"ADLB",
ADLB,
code = "ADLB <- teal.modules.general::rADLB %>%
mutate(CHGC = as.factor(case_when(
CHG < 1 ~ 'N',
CHG > 1 ~ 'P',
TRUE ~ '-'
)))"
),
check = TRUE
),
data = data,
modules = teal::modules(
# tm_g_association ----
modules(
Expand All @@ -95,7 +93,7 @@ app <- teal::init(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL),
choices = variable_choices(data@env$ADSL),
selected = "AGE",
fixed = FALSE
)
Expand All @@ -104,7 +102,7 @@ app <- teal::init(
dataname = "ADSL",
select = select_spec(
label = "Select variables:",
choices = variable_choices(ADSL),
choices = variable_choices(data@env$ADSL),
selected = "BMRKR1",
multiple = TRUE,
fixed = FALSE
Expand All @@ -117,7 +115,7 @@ app <- teal::init(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, c("AGE", "SEX", "STRATA1", "RACE")),
choices = variable_choices(data@env$ADSL, c("AGE", "SEX", "STRATA1", "RACE")),
selected = "STRATA1",
multiple = FALSE,
fixed = FALSE
Expand All @@ -127,7 +125,7 @@ app <- teal::init(
dataname = "ADSL2",
select = select_spec(
label = "Select variables:",
choices = variable_choices(ADSL2, c("AGE", "SEX", "RACE", "COUNTRY")),
choices = variable_choices(data@env$ADSL2, c("AGE", "SEX", "RACE", "COUNTRY")),
selected = c("AGE", "COUNTRY", "RACE"),
multiple = TRUE,
fixed = FALSE
Expand All @@ -140,15 +138,15 @@ app <- teal::init(
dataname = "ADTTE",
select = select_spec(
label = "Select variables:",
choices = variable_choices(ADTTE),
choices = variable_choices(data@env$ADTTE),
selected = "AVAL",
multiple = FALSE,
fixed = FALSE
),
filter = teal.transform::filter_spec(
label = "Select endpoint:",
vars = "PARAMCD",
choices = value_choices(ADTTE, "PARAMCD", "PARAM"),
choices = value_choices(data@env$ADTTE, "PARAMCD", "PARAM"),
selected = c("PFS", "EFS"),
multiple = TRUE
)
Expand All @@ -158,7 +156,7 @@ app <- teal::init(
reshape = TRUE,
select = select_spec(
label = "Select variable:",
choices = variable_choices(ADRS, c("AVALC", "BMRKR1", "BMRKR2", "ARM")),
choices = variable_choices(data@env$ADRS, c("AVALC", "BMRKR1", "BMRKR2", "ARM")),
selected = "AVALC",
multiple = TRUE,
fixed = FALSE
Expand All @@ -167,14 +165,14 @@ app <- teal::init(
filter_spec(
label = "Select endpoints:",
vars = "PARAMCD",
choices = value_choices(ADRS, "PARAMCD", "PARAM"),
choices = value_choices(data@env$ADRS, "PARAMCD", "PARAM"),
selected = "BESRSPI",
multiple = TRUE
),
filter_spec(
label = "Select endpoints:",
vars = "AVISIT",
choices = levels(ADRS$AVISIT),
choices = levels(data@env$ADRS$AVISIT),
selected = "SCREENING",
multiple = TRUE
)
Expand All @@ -186,7 +184,7 @@ app <- teal::init(
ref = teal.transform::data_extract_spec(
dataname = "ADRS",
select = select_spec(
choices = variable_choices(ADRS, c("AVAL", "AVALC")),
choices = variable_choices(data@env$ADRS, c("AVAL", "AVALC")),
selected = "AVALC",
multiple = FALSE,
fixed = FALSE,
Expand All @@ -195,15 +193,15 @@ app <- teal::init(
filter = list(
filter_spec(
vars = "PARAMCD",
choices = value_choices(ADRS, "PARAMCD", "PARAM"),
selected = levels(ADRS$PARAMCD),
choices = value_choices(data@env$ADRS, "PARAMCD", "PARAM"),
selected = levels(data@env$ADRS$PARAMCD),
multiple = TRUE,
label = "Select response"
),
filter_spec(
vars = "AVISIT",
choices = levels(ADRS$AVISIT),
selected = levels(ADRS$AVISIT),
choices = levels(data@env$ADRS$AVISIT),
selected = levels(data@env$ADRS$AVISIT),
multiple = TRUE,
label = "Select visit:"
)
Expand All @@ -212,7 +210,7 @@ app <- teal::init(
vars = teal.transform::data_extract_spec(
dataname = "ADSL",
select = select_spec(
choices = variable_choices(ADSL, c("SEX", "AGE", "RACE", "COUNTRY", "BMRKR1", "STRATA1", "ARM")),
choices = variable_choices(data@env$ADSL, c("SEX", "AGE", "RACE", "COUNTRY", "BMRKR1", "STRATA1", "ARM")),
selected = "AGE",
multiple = TRUE,
fixed = FALSE,
Expand All @@ -225,7 +223,7 @@ app <- teal::init(
ref = teal.transform::data_extract_spec(
dataname = "ADRS",
select = select_spec(
choices = variable_choices(ADRS),
choices = variable_choices(data@env$ADRS),
selected = "AVALC",
multiple = FALSE,
fixed = FALSE,
Expand All @@ -235,7 +233,7 @@ app <- teal::init(
vars = teal.transform::data_extract_spec(
dataname = "ADRS",
select = select_spec(
choices = variable_choices(ADRS),
choices = variable_choices(data@env$ADRS),
selected = "PARAMCD",
multiple = TRUE,
fixed = FALSE,
Expand All @@ -250,21 +248,21 @@ app <- teal::init(
filter = list(
filter_spec(
vars = "PARAMCD",
choices = value_choices(ADLB, "PARAMCD", "PARAM"),
selected = levels(ADLB$PARAMCD)[1],
choices = value_choices(data@env$ADLB, "PARAMCD", "PARAM"),
selected = levels(data@env$ADLB$PARAMCD)[1],
multiple = FALSE,
label = "Select lab:"
),
filter_spec(
vars = "AVISIT",
choices = levels(ADLB$AVISIT),
selected = levels(ADLB$AVISIT)[1],
choices = levels(data@env$ADLB$AVISIT),
selected = levels(data@env$ADLB$AVISIT)[1],
multiple = FALSE,
label = "Select visit:"
)
),
select = select_spec(
choices = variable_choices(ADLB, c("AVAL", "CHG2", "PCHG2")),
choices = variable_choices(data@env$ADLB, c("AVAL", "CHG2", "PCHG2")),
selected = "AVAL",
multiple = FALSE
)
Expand All @@ -274,21 +272,21 @@ app <- teal::init(
filter = list(
filter_spec(
vars = "PARAMCD",
choices = value_choices(ADLB, "PARAMCD", "PARAM"),
selected = levels(ADLB$PARAMCD)[1],
choices = value_choices(data@env$ADLB, "PARAMCD", "PARAM"),
selected = levels(data@env$ADLB$PARAMCD)[1],
multiple = FALSE,
label = "Select labs:"
),
filter_spec(
vars = "AVISIT",
choices = levels(ADLB$AVISIT),
selected = levels(ADLB$AVISIT)[1],
choices = levels(data@env$ADLB$AVISIT),
selected = levels(data@env$ADLB$AVISIT)[1],
multiple = FALSE,
label = "Select visit:"
)
),
select = select_spec(
choices = variable_choices(ADLB),
choices = variable_choices(data@env$ADLB),
selected = "STRATA1",
multiple = TRUE
)
Expand Down
Loading

0 comments on commit d09651f

Please sign in to comment.