---
title: LBT04
subtitle: Laboratory Abnormalities Not Present at Baseline
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(tern)
adsl <- random.cdisc.data::cadsl
adlb <- random.cdisc.data::cadlb
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adlb <- df_explicit_na(adlb)
adlb_f <- adlb %>%
filter(ONTRTFL == "Y", ANRIND != "<Missing>") %>%
var_relabel(
PARAM = "Laboratory Test",
ANRIND = "Direction of Abnormality"
)
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::: panel-tabset
## Standard Table
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM") %>%
split_rows_by("PARAM",
split_fun = drop_split_levels,
label_pos = "topleft",
split_label = obj_label(adlb_f$PARAM)
) %>%
count_abnormal(
var = "ANRIND",
abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH")),
exclude_base_abn = TRUE
) %>%
append_varlabels(adlb_f, "ANRIND", indent = 1L)
result <- build_table(lyt = lyt, df = adlb_f, alt_counts_df = adsl)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
::::
{{< include ../../_utils/save_results.qmd >}}
## `teal` App
::: {.panel-tabset .nav-justified}
## {{< fa regular file-lines fa-sm fa-fw >}} Preview
```{r teal, opts.label = c("skip_if_testing", "app")}
library(teal.modules.clinical)
## Data reproducible code
data <- teal_data()
data <- within(data, {
ADSL <- random.cdisc.data::cadsl
ADLB <- random.cdisc.data::cadlb %>%
col_relabel(PARAM = "Laboratory Test", ANRIND = "Direction of Abnormality")
})
datanames <- c("ADSL", "ADLB")
names(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
## Reusable Configuration For Modules
ADSL <- data[["ADSL"]]
ADLB <- data[["ADLB"]]
## Setup App
app <- init(
data = data,
modules = modules(
tm_t_abnormality(
label = "Abnormality Table",
dataname = "ADLB",
arm_var = choices_selected(
choices = variable_choices(ADSL, subset = c("ARM", "ARMCD")),
selected = "ARM"
),
by_vars = choices_selected(
choices = variable_choices(ADLB, subset = c("LBCAT", "PARAM", "AVISIT")),
selected = c("LBCAT", "PARAM"),
keep_order = TRUE
),
grade = choices_selected(
choices = variable_choices(ADLB, subset = "ANRIND"),
selected = "ANRIND",
fixed = TRUE
),
abnormal = list(low = "LOW", high = "HIGH"),
exclude_base_abn = TRUE
)
)
)
shinyApp(app$ui, app$server)
```
{{< include ../../_utils/shinylive.qmd >}}
:::
{{< include ../../repro.qmd >}}