
Make UI and server functions for Shiny apps based on data supplied as modfied SummarizedExperiments
Source:R/apps.R
prepare_app.RdDraws on various components (heatmaps, tables etc) to produce the UI and server components of a variety of shiny apps, based on the type and data specified, using modularised Shiny components.
Arguments
- type
A string specifying the type of shiny app required. Currently, 'rnaseq' or 'chipseq' produce large multi-panel applications designed to facilitate analysis of those data types. For any other 'type', the call is passed to
simpleApp(), which will attempt to build an application usingInputandOutputfunctions of the same module.- eselist
An ExploratorySummarizedExperimentList object containing assay data (expression, counts...), sample data and annotation data for the rows.
- ui_only
Don't add server components (for UI testing)
- ...
Additional arguments passed to
simpleApp()
Examples
library(shinyngs)
# 1: BASIC RNA-SEQ APP
# Get an example RNA-seq dataset from the `airway` package
data(airway, package = "airway")
# Get some information about these data from the package description
expinfo <- packageDescription("airway")
# Convert to an ExploratorySummarizedExperiment (with extra slots)
ese <- as(airway, "ExploratorySummarizedExperiment")
# Make the ExploratorySummarizedExperimentList that represents the study as a
# whole.
eselist <- ExploratorySummarizedExperimentList(
ese,
title = expinfo$Title,
author = expinfo$Author,
description = expinfo$Description
)
#> Creating ExploratorySummarizedExperimentList object
# Make and run the app
if (interactive()) {
app <- prepare_app("rnaseq", eselist)
shiny::shinyApp(ui = app$ui, server = app$server)
}
# 2: AUGMENT WITH ANNOTATION INFO FOR MORE INFORMATIVE APP
# Add row metadata (gene symbol, genomic coordinates) so plots and tables
# are labelled meaningfully, then choose a different default grouping
# variable and re-make the app. Any source of per-gene annotation works
# here (a GTF, an annotation package, a pre-built CSV); the requirement is
# a data.frame keyed by the same IDs as rownames(ese). Adding
# chromosome_name/start_position/end_position columns plus ensembl_species
# also enables the igv.js gene model view on the gene page.
if (interactive()) {
annotation <- data.frame(
ensembl_gene_id = rownames(ese),
external_gene_name = rownames(ese), # substitute real gene symbols
chromosome_name = "1", # substitute real coordinates
start_position = seq_along(rownames(ese)),
end_position = seq_along(rownames(ese)) + 1000
)
mcols(ese) <- annotation[match(rownames(ese), annotation$ensembl_gene_id), ]
ese@labelfield <- "external_gene_name"
eselist <- ExploratorySummarizedExperimentList(
ese,
title = expinfo$Title,
author = expinfo$Author,
description = expinfo$Description,
default_groupvar = "dex",
ensembl_species = "hsapiens" # enables the igv.js gene model view
)
app <- prepare_app("rnaseq", eselist)
shiny::shinyApp(ui = app$ui, server = app$server)
}
# 3. MORE COMPLEX DATA FOR DIFFERENTIAL EXPRESSION ETC
# See the vignette for how to populate the extra slots of an
# ExploratorySummarizedExperimentList (contrasts, differential statistics,
# gene set analyses etc.). With those in place the resulting app gains
# additional panels for differential analyses.