1
$\begingroup$

I am trying to build a shiny dashboard for the visualization of different RNAseq data sets.

However, I am encountering problem with reactive input, the code is always using the second dataset that I have loaded/read in. Anyone has faced a similar issue? If yes, how did you resolve it.

My code is

    library(shinydashboard)
library(uwot)
library(DESeq2)
library(gridExtra)
library(tidyverse)
library(RColorBrewer)
library(DESeq2)
library(pheatmap)
library(DEGreport)
library(vsn)
library(RColorBrewer)
library("genefilter")
library(org.Hs.eg.db)
library(dplyr)
library(tidyverse)
library(fgsea)
library(clusterProfiler)
library(ggplot2)


set_1<-load("C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData2.RData")
set_2<-load("C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData1.RData")
data_list = list(set_1=set_1,set_2=set_2)

ui <- dashboardPage(
    dashboardHeader(title = "Data Visualizer", titleWidth = 300),
    dashboardSidebar(
        width = 300,
        sidebarMenu(

            menuItem("Datasets",  icon = icon("cog"),
                     selectInput("Datasets", "Datasets:", choices = list("sample1" = "set_1", "sample2" = "set_2"),
                                 selected = "set_1")),
            menuItem("Quality Control", tabName = "widgets", icon = icon("th")),
            menuItem("Differential Genes", tabName = "widgets2", icon = icon("th")),
            menuItem("Downstream", tabName = "widgets3", icon = icon("th"))
            
         )
    ),
    ## Body content
    dashboardBody(
        tabItems(
            # First tab content
            # Second tab content
            tabItem(tabName="widgets",
                   h2("widgets"),
                   plotOutput("widgets"),
                    
            ),
            tabItem(tabName = "widgets2",
                    h2("Widgets2 tab content"),
                    
            ),
            tabItem(tabName = "widgets3",
                    h2("Widgets3 tab content"),
                    plotOutput("widgets3"),
                    
            )

        )
    )
)


server <- function(input, output) {

    
    datasetInput <- reactive({
        df <- data_list[[input$Datasets]]
        })
    
        output$widgets <- renderPlot({
            datasetInput()
            par(mfrow=c(1,2))
            
            boxplot(counts(dds, normalized=F), outline=F, col=dds$condition, medcol = "white", cex.axis=0.6, main="Without Normalization")
            boxplot(counts(dds, normalized=T), outline=F, col=dds$condition, medcol = "white", cex.axis=0.6, main="Normalized")
            
            })
        
        }

shinyApp(ui, server)
$\endgroup$
1
$\begingroup$

There are two issues that I can see.

The first is that the results are loaded via RData files, which include information about the variable names. Assuming these work, I expect they create a variable within the R environment called dds which has the DESeq2 results. The second load overwrites that variable:

set_1<-load("C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData2.RData")
set_2<-load("C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData1.RData")

What should probably be done is storing the results as an R Dataset that doesn't include variable name information:

# create set_1 DESeq2 results called 'dds'
saveRDS(dds, "C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData2.rds")
# create set_2 DESeq2 results called 'dds'
saveRDS(dds, "C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData1.rds")

Then those can be loaded into the R environment using the assignment you expect:

set_1<-readRDS("C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData2.RData")
set_2<-readRDS("C:/Users/abn/Documents/Shiny/DashBoardTutorial/TeData1.RData")
data_list = list(set_1=set_1,set_2=set_2)

The second issue is that the plot output displays dds, rather than the datasetInput variable, and there is no assignment to change the definition of dds:

    output$widgets <- renderPlot({
        dds <- datasetInput() ## Note: added assignment
        par(mfrow=c(1,2))
        
        boxplot(counts(dds, normalized=F), outline=F, col=dds$condition, medcol = "white", cex.axis=0.6, main="Without Normalization")
        boxplot(counts(dds, normalized=T), outline=F, col=dds$condition, medcol = "white", cex.axis=0.6, main="Normalized")
        
        })
    
    }
$\endgroup$
1
  • 1
    $\begingroup$ Thank you, your tips were very helpful $\endgroup$
    – Angelo
    Aug 1 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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