Error loading data into Shiny App using Seurat

I am trying to build a shiny app to aid in the analysis of some data but keep getting this error from my server. I don't really understand the error message I get, and Google doesn't seem to be too helpful with the error.

The error message is shown below:

Warning: Error in UseMethod: no applicable method for 'DefaultAssay' applied to an object of class "c('reactiveExpr', 'reactive', 'function')"

This is what my server.py looks like:


if (!require('pacman')) install.packages("pacman")

# Load contributed packages with pacman
pacman::p_load(pacman, Seurat, tidyverse, shiny)


load_data <- function(project, cells = 3, features){
    # Load the PBMC dataset
    reads <- Read10X(data.dir = "data/pbmc3k/filtered_gene_bc_matrices/hg19/")
    # Initialize the Seurat object with the raw (non-normalized data).
    cts <- reads$`Gene Expression`
    datum <- CreateSeuratObject(
            cts, 
            project = project, 
            min.cells = as.numeric(cells), 
            min.features = as.numeric(features)
            )
    
    return(datum)
}

metricsplot <- function(data){
  # seurat_object <- load_data(project, cells, features)
  data[["percent.mt"]] <- PercentageFeatureSet(data, pattern = "^MT-")
  plt <- VlnPlot(data, 
                 features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), 
                 ncol = 3)
  return(plt)
}

featureplot <- function(data){
  data[["percent.mt"]] <- PercentageFeatureSet(data, pattern = "^MT-")
  plot1 <- FeatureScatter(data, feature1 = "nCount_RNA", feature2 = "percent.mt")
  plot2 <- FeatureScatter(data, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
  return (plot1 + plot2)
}

server <- function(input, output, session) {
  seurat_obj <- reactive({
    load_data(input$proj_name, input$min.cells, input$min.feats)
    })
  output$metrics <- renderPlot(metricsplot(seurat_obj))
  output$features <- renderPlot(featureplot(seurat_obj))
  
}

Thanks for your help. It is greatly appreciated.

Cheers!

in R shiny you have reactive expressions (i.e. seurat_obj <- reactive({)
if you want to use the content of the reactive anywhere you can't call it by its bare name or what will appear to be the content is the defitinion of the reactive, which you dont want; you get the 'true' content by using bracket syntax, treating the reactive as a function that you want data out of . i.e.

  output$metrics <- renderPlot(metricsplot(seurat_obj()))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.