Skip to contents

Cell embeddings module

Usage

dimredUI(id, panel)

dimredServer(
  id,
  obj,
  filtered,
  args,
  all_selected,
  show_selection,
  reset_selection,
  reload_global,
  config
)

Arguments

id

Input id

panel

string, can be 'sidebar' or 'main'

obj

Cascade app object

filtered

barcodes to filter object

args

reactive list with global args, 'grp_by' for grouping variable and 'dimred' for which dimension reduction to use

all_selected

reactive containing list of selected points

show_selection

reactive to show selection

reset_selection

reactive to reset selection

reload_global

reactive to trigger reload

config

reactive list with config settings

Value

UI returns sidebar/main panel UI elements for cell embeddings Server returns reactive expression containing selected points from embedding plots

Examples

if (FALSE) { # interactive()
# example obj
obj <- make_example_seurat_object()

# prep metadata
metadata <- obj[[]]
metadata_levels <- lapply(
  metadata[c("cluster", "condition", "orig.ident", "seurat_clusters")],
  levels
)

# get grouping vars and colors
grouping_vars <- names(metadata_levels)
names(grouping_vars) <- paste0(
  grouping_vars,
  " (n = ",
  lengths(metadata_levels),
  ")"
)
cluster_colors <- lapply(metadata_levels, function(lvls) {
  stats::setNames(rep_len(c("#4477aa", "#cc6677"), length(lvls)), lvls)
})

app_object <- list(
  rds = obj,
  obj_type = "seurat",
  metadata = metadata,
  metadata_levels = list(
    all = metadata_levels,
    filtered = metadata_levels
  ),
  cluster_colors = cluster_colors,
  grouping_vars = grouping_vars,
  spatial_coords = NULL,
  imagerow_max = NULL,
  imagerow_min = NULL
)

global_args <- list(
  grp_by = "cluster",
  dimred = "umap"
)

config <- get_config()

ui <- shiny::fluidPage(
  shinyjs::useShinyjs(),
  shiny::sidebarLayout(
    shiny::sidebarPanel(dimredUI("dimred", "sidebar")),
    shiny::mainPanel(
      dimredUI("dimred", "main"),
      shiny::verbatimTextOutput("selected")
    )
  )
)

server <- function(input, output, session) {
  selected <- dimredServer(
    "dimred",
    obj = app_object,
    filtered = shiny::reactive({ colnames(obj) }),
    args = shiny::reactive({ global_args }),
    all_selected = shiny::reactive({ list() }),
    show_selection = shiny::reactive({ NULL }),
    reset_selection = shiny::reactive({ NULL }),
    reload_global = shiny::reactiveVal(0),
    config = shiny::reactive({ config })
  )

  output$selected <- shiny::renderPrint({
    selected()
  })
}

shiny::shinyApp(ui, server)
}