Skip to contents

[Stable] Extracting details of the selection(s) in data_extract_ui elements.

Usage

data_extract_srv(id, datasets, data_extract_spec)

Arguments

id

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

datasets

(FilteredData)
object containing data, see teal.slice::FilteredData for more.

data_extract_spec

(data_extract_spec or a list of data_extract_spec)
A list of data filter and select information constructed by data_extract_spec.

Value

A reactive list containing following fields:

  • filters: A list with the information on the filters that are applied to the data set.

  • select: The variables that are selected from the dataset.

  • always_selected: The column names from the data set that should always be selected.

  • reshape: Whether reshape long to wide should be applied or not.

  • dataname: The name of the data set.

  • internal_id: The id of the corresponding shiny input element.

  • keys: The names of the columns that can be used to merge the data set.

References

data_extract_srv

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)
)
data <- teal.data::teal_data(teal.data::dataset("ADSL", ADSL))
datasets <- teal.slice:::filtered_data_new(data)
teal.slice:::filtered_data_set(data, datasets)

adsl_extract <- data_extract_spec(
  dataname = "ADSL",
  filter = filter_spec(vars = "SEX", choices = c("F", "M"), selected = "F"),
  select = select_spec(
    label = "Select variable:",
    choices = variable_choices(ADSL, c("AGE", "BMRKR1")),
    selected = "AGE",
    multiple = TRUE,
    fixed = FALSE
  )
)

app <- shinyApp(
  ui = fluidPage(
    teal.widgets::standard_layout(
      output = verbatimTextOutput("out1"),
      encoding = tagList(
        data_extract_ui(
          id = "adsl_var",
          label = "ADSL selection",
          data_extract_spec = adsl_extract
        )
      )
    )
  ),
  server = function(input, output, session) {
    adsl_reactive_input <- data_extract_srv(
      id = "adsl_var",
      datasets = datasets,
      data_extract_spec = adsl_extract
    )
    output$out1 <- renderPrint({
      print(adsl_reactive_input())
    })
  }
)
if (FALSE) {
runApp(app)
}