Skip to contents

[Experimental]

This defines the server part for the experiment specification.

Usage

experimentSpecServer(
  id,
  datasets,
  mae_name,
  name_annotation = "symbol",
  sample_vars_as_factors = TRUE,
  with_mae_col_data = TRUE
)

Arguments

id

(string) the shiny module id.

datasets

(Datasets)
teal specific argument which is automatically passed to the UI and server functions, holding all the data sets provided in the app initialization.

mae_name

(string)
name of the MAE data used in the teal module.

name_annotation

(string or NULL)
which annotation column to use as name to return in the genes data. If NULL, then the name column will be set to empty strings.

sample_vars_as_factors

(flag)
whether to convert the sample variables (columns in colData() of the experiment) from character to factor variables.

with_mae_col_data

(flag)
whether to include the colData() of the MAE into the experiment colData().

Value

List with the following reactive objects:

  • data: the hermes::AnyHermesData experiment.

  • name: the name of the experiment as selected by the user.

  • genes: a data.frame with the genes in data, with columns id and name.

  • assays: the names of the assays in data.

See also

experimentSpecInput() for the module UI.

Examples

ui <- function(id,
               datasets,
               mae_name) {
  ns <- NS(id)
  teal.widgets::standard_layout(
    encoding = div(
      experimentSpecInput(
        ns("my_experiment"),
        datasets,
        mae_name,
        label_experiments = "Please choose experiment"
      ),
      selectInput(
        ns("property"),
        "Please choose property",
        c("data", "name", "genes", "assays")
      )
    ),
    output = div(
      verbatimTextOutput(ns("summary")),
      verbatimTextOutput(ns("head"))
    )
  )
}

server <- function(id,
                   datasets,
                   mae_name) {
  moduleServer(id, function(input, output, session) {
    experiment <- experimentSpecServer(
      "my_experiment",
      datasets,
      mae_name
    )
    result <- reactive({
      switch(input$property,
        data = experiment$data(),
        name = experiment$name(),
        genes = experiment$genes(),
        assays = experiment$assays()
      )
    })
    output$summary <- renderPrint({
      result <- result()
      hermes::summary(result)
    })
    output$head <- renderPrint({
      result <- result()
      utils::head(result)
    })
  })
}

my_app <- function() {
  mae <- hermes::multi_assay_experiment
  mae_name <- "MAE"
  mae_data <- dataset(mae_name, mae)
  data <- teal_data(mae_data)
  app <- init(
    data = data,
    modules = modules(
      module(
        label = "experimentSpec example",
        server = server,
        server_args = list(mae_name = mae_name),
        ui = ui,
        ui_args = list(mae_name = mae_name),
        filters = "all"
      )
    )
  )
  shinyApp(app$ui, app$server)
}
if (interactive()) {
  my_app()
}