Skip to contents

[Experimental]

Usage

data_merge_srv(
  id = "merge_id",
  selector_list,
  datasets,
  merge_function = "dplyr::full_join",
  anl_name = "ANL"
)

Arguments

id

An ID string that corresponds with the ID used to call the module's UI function.

selector_list

(reactive)
output from data_extract_multiple_srv() or a reactive named list of outputs from data_extract_srv(). When using a reactive named list, the names must be identical to the shiny ids of the respective data_extract_ui().

datasets

(FilteredData)
object containing data (see teal.slice::FilteredData).

merge_function

(character(1) or reactive)
A character string of a function that accepts the arguments x, y and by to perform the merging of datasets.

anl_name

(character(1))
Name of the analysis dataset.

Value

reactive expression with output from merge_datasets.

Details

When additional processing of the data_extract list input is required, data_merge_srv() can be combined with data_extract_multiple_srv() or data_extract_srv() to influence the selector_list input. Compare the example below with that found in data_merge_module().

Examples

library(shiny)

ADSL <- data.frame(
  STUDYID = "A",
  USUBJID = LETTERS[1:10],
  SEX = rep(c("F", "M"), 5),
  AGE = rpois(10, 30),
  BMRKR1 = rlnorm(10)
)
ADLB <- expand.grid(
  STUDYID = "A",
  USUBJID = LETTERS[1:10],
  PARAMCD = c("ALT", "CRP", "IGA"),
  AVISIT = c("SCREENING", "BASELINE", "WEEK 1 DAY 8", "WEEK 2 DAY 15")
)
ADLB$AVAL <- rlnorm(120)
ADLB$CHG <- rnorm(120)

data <- teal.data::cdisc_data(
  teal.data::cdisc_dataset("ADSL", ADSL),
  teal.data::cdisc_dataset("ADLB", ADLB)
)
datasets <- teal.slice:::filtered_data_new(data)
teal.slice:::filtered_data_set(data, datasets)

adsl_extract <- data_extract_spec(
  dataname = "ADSL",
  select = select_spec(
    label = "Select variable:",
    choices = c("AGE", "BMRKR1"),
    selected = "AGE",
    multiple = TRUE,
    fixed = FALSE
  )
)
adlb_extract <- data_extract_spec(
  dataname = "ADLB",
  filter = filter_spec(vars = "PARAMCD", choices = c("ALT", "CRP", "IGA"), selected = "ALT"),
  select = select_spec(
    label = "Select variable:",
    choices = c("AVAL", "CHG"),
    selected = "AVAL",
    multiple = TRUE,
    fixed = FALSE
  )
)

app <- shinyApp(
  ui = fluidPage(
    teal.widgets::standard_layout(
      output = div(
        verbatimTextOutput("expr"),
        dataTableOutput("data")
      ),
      encoding = tagList(
        data_extract_ui("adsl_var", label = "ADSL selection", adsl_extract),
        data_extract_ui("adlb_var", label = "ADLB selection", adlb_extract)
      )
    )
  ),
  server = function(input, output, session) {
    selector_list <- data_extract_multiple_srv(
      list(adsl_var = adsl_extract, adlb_var = adlb_extract),
      datasets
    )
    merged_data <- data_merge_srv(
      selector_list = selector_list,
      datasets = datasets,
      merge_function = "dplyr::left_join"
    )
    output$expr <- renderText(merged_data()$expr)
    output$data <- renderDataTable(merged_data()$data())
  }
)
if (FALSE) {
runApp(app)
}