2
$\begingroup$

I am trying to create a shiny board for my scRNA seq data. I have saved my seurat objects adn I use following code as below:

library(shiny)
library(shinythemes)
library(Seurat)
library(uwot)


set_1 <- readRDS("/temp2/data/mydataB10.rds")
set_2 <- readRDS("/temp2/data/mydataB5.rds")

ui <- fluidPage(
    
    # Application title
    titlePanel("scRNAseq data browser"),
    
    fluidRow(
        column(4,
               
               sidebarPanel(
                   radioButtons("dataset", label = h3("Dataset"),
                                choices = list("sample1" = "set_1", "sample2" = "set_2"),
                                selected = "set_1"),
                   helpText("Enter gene names in CAPS.  Gene names must be exact."),
                   textInput("gene2", label = "Gene Name", value = "GAPDH")
                   
               )
        ),
        column(8,
               column(6, 
                      mainPanel(
                          plotOutput("dimPlot1", width = "150%"),
                          plotOutput("genePlot2", width = "150%")
                      )
               )
        )
    )
)


server <- function(input, output, session) {
    
    datasetInput <- reactive({
        df <- (input$dataset)
            })
    
    output$dimPlot1 <- renderPlot({
        DimPlot(datasetInput(), reduction = "umap")
    })
    
    output$genePlot2 <- renderPlot({
        FeaturePlot(datasetInput(), features = (input$gene2), reduction = "umap")
    })
    
}

shinyApp(ui, server)  

That error that I get on the section where image needs to be displayed is "Subscript out of bound".

Following dataset can be downloaded and used as an example curl -Lo pbmc_10k_v3.rds https://www.dropbox.com/s/3f3p5nxrn5b3y4y/pbmc_10k_v3.rds?dl=1

Can anyone help in fixing this shiny script so that it works.

Many thanks.

$\endgroup$

1 Answer 1

3
$\begingroup$

Not easy to reproduce your error but here is my guess. This is a string, you can check it:

input$dataset
class(input$dataset)

This is a simple solution. If you want to call out the dataset depending on input, use a list:

set_1 <- readRDS("/temp2/data/mydataB10.rds")
set_2 <- readRDS("/temp2/data/mydataB5.rds")
data_list = list(set_1=set_1,set_2=set_2)

Then in the server :

datasetInput <- reactive({
        df <- data_list[[input$dataset]]
            })
$\endgroup$
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.