Search code examples
rshinyseurat

R/Shiny: Subscript out of bounds error despite working in R


I've seen many people with issues like mine, but no answers have been helpful for my case.

I am using seurat for single cell data analysis and I'm trying to build a very simple web page for other individuals to query their gene expression.

I get a "subscript out of bounds" error while trying to run my Shiny app immediately on launch, despite it working in R.

In the console, it's immediately displaying -- Warning: Error in [[: subscript out of bounds. What am I doing wrong here?

library(shiny)
library(Seurat)

WholeEye <- readRDS("WholeEye.rds")
MG <- readRDS("MG.rds")
CMZ <- readRDS("CMZ.rds")
RPE <- readRDS("CMZ.rds")

ui <- fluidPage(
  headerPanel('McFarlane scRNAseq'),
  sidebarPanel(
    textInput(inputId = 'celltype', label = "Choose a cell type. Eg. WholeEye, MG, RPE, CMZ", value = "MG", width = NULL, placeholder = NULL),

    textInput(inputId = 'gene', label = "Choose a gene", value = "", width = NULL, placeholder = NULL)
  ),
  mainPanel(
    plotOutput(outputId = "FeaturePlot" )
  )
)

server <- function(input, output) {
  
  output$FeaturePlot <- renderPlot({
    
    FeaturePlot(object = input$celltype, reduction = "umap", label = TRUE, min.cutoff = 0, features = input$gene)
    
    
    
  })
 
}

shinyApp(ui = ui, server = server)

Solution

  • Try

    output$FeaturePlot <- renderPlot({
      req(input$celltype,input$gene)
      FeaturePlot(object = get(input$celltype), reduction = "umap", label = TRUE, min.cutoff = 0, features = get(input$gene))
    })