library(random.cdisc.data)
library(teal)
library(teal.transform)
library(teal.widgets)
library(tern)
library(dplyr)
<- list(
modules module(
label = "Adhoc module",
server = function(id, data){
moduleServer(id, function(input, output, session){
<- function(x) {
s_summary if (is.numeric(x)) {
in_rows(
"n" = rcell(sum(!is.na(x)), format = "xx"),
"Mean (sd)" = rcell(c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE)), format = "xx.xx (xx.xx)"),
"IQR" = rcell(IQR(x, na.rm = TRUE), format = "xx.xx"),
"min - max" = rcell(range(x, na.rm = TRUE), format = "xx.xx - xx.xx")
)else if (is.factor(x)) {
} <- as.list(table(x))
vs do.call(in_rows, lapply(vs, rcell, format = "xx"))
else {
} stop("type not supported")
}
}
observe({
<- get_var(data(), "ADSL")
ADSL req(ADSL)
updateSelectInput(
inputId = "param",
choices = variable_choices(ADSL),
selected = c("AGE"),
)
})
<- reactive({
table_q data() |>
within(
{<- my_summary
s_summary <- basic_table() %>%
summary_lyt split_cols_by(var = "ARM") %>%
analyze(param, afun = s_summary)
<- build_table(summary_lyt, ADSL)
summary_tbl
summary_tbl
},my_summary = s_summary,
param = input$param
)
})
$table = renderUI({
outputrenderPrint(table_q()[["summary_tbl"]])
})
})
},ui = function(id) {
<- NS(id)
ns
standard_layout(
output = div(
fluidRow(
column(
width = 12,
br(), hr(),
uiOutput(ns("table"))
)
)
),encoding = div(
br(),
$label('Encodings', class = 'text-primary'),
tagshelpText('Analysis Data:', tags$code('ADSL')),
selectInput(
inputId = ns('param'),
label = 'Demographic Parameter',
choices = NULL,
selected = NULL,
multiple = TRUE
)
)
)
},datanames = c("ADSL")
)
)
<- teal_data()
data <- within(data, {
data <- radsl(cached = TRUE)
ADSL
})datanames(data) <- c("ADSL")
<- init(
app data = data,
modules = modules
)
if (Sys.getenv("QUARTO_ROOT") == "") {
shinyApp(app$ui, app$server)
}
Exercise 3
Create your custom module!
Create a custom module that does a simple demographic summary table on user specified columns.
- read
teal::module()
documentation - read “Creating Custom Modules” vignette
- read
"qenv"
article on how to interact with internalqenv
object - in particular:teal.code::within()
function