Browse code

Adding shiny app features

pablo-rodr-bio2 authored on 26/05/2020 16:32:08
Showing2 changed files

... ...
@@ -1,10 +1,12 @@
1 1
 library(GSVA)
2 2
 library(shiny)
3 3
 library(shinythemes)
4
-library(geneplotter)
5 4
 library(GSEABase)
6 5
 library(GSVAdata)
7 6
 library(limma)
7
+library(ggplot2)
8
+library(data.table)
9
+library(plotly)
8 10
 
9 11
 argumentsDataInput <- function(id) {
10 12
   # Create a namespace function using the provided id
... ...
@@ -111,7 +113,7 @@ gsva_validation <- function(input, output, session) {
111 113
   }
112 114
   else
113 115
   {
114
-    #User selects matrix varand geneset file
116
+    #User selects matrix var and geneset file
115 117
     if(input$genesetSourceType == "fileGeneset")
116 118
     {
117 119
       if (is.null(input$genesetFile))
... ...
@@ -169,7 +171,7 @@ gsva_generation <- function(input, output, session, newY, genes,varMaxsz) {
169 171
             selectedTau <- NULL
170 172
           }
171 173
   )
172
-  #GSVA Generation
174
+  # GSVA Generation
173 175
   withProgress(message = 'Runing GSVA', value = 0, {
174 176
     incProgress(1, detail = "This may take a while...")
175 177
     generated_gsva <<- gsva(newY, genes, method=input$method, kcdf=input$kcdf,
... ...
@@ -181,6 +183,7 @@ gsva_generation <- function(input, output, session, newY, genes,varMaxsz) {
181 183
                             ssgsea.norm=as.logical(input$ssgseaNorm),
182 184
                             verbose=as.logical(input$verbose))
183 185
   })
186
+
184 187
 }
185 188
 
186 189
 gsva_information <- function(input, output, session) {
... ...
@@ -193,13 +196,28 @@ gsva_information <- function(input, output, session) {
193 196
     gsva_es <- as.data.frame(assays(generated_gsva)[[1]])
194 197
   else
195 198
     stop("Unknown output generated by the call to the 'gsva()' function.")
196
-
199
+  
200
+  # Rendering table
197 201
   resultInformation <- matrix(data = c(nrow(generated_gsva),
198 202
                                        ncol(generated_gsva)),
199 203
                                        nrow = 1, ncol = 2)
200 204
   colnames(resultInformation) <- c("Nr. of gene sets", "Nr. of samples")
201 205
   output$result <- renderTable(resultInformation)
202
-  output$plot <- renderPlot(multidensity(as.list(as.data.frame(generated_gsva)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2, cex.axis=1.2, cex.lab=1.5))
206
+  
207
+  # Rendering graph
208
+  dat.t <- melt(as.data.table(generated_gsva), variable.name = "Sample")
209
+  output$plot <- renderPlotly({
210
+    p <- ggplot(data = dat.t, aes(x=value, color=Sample)) +
211
+      stat_density(geom="line", position = "identity") +
212
+      theme(legend.position = "none") + labs(x="GSVA Scores", y="Density")
213
+    ggplotly(p, tooltip = "Sample")
214
+  })
215
+  
216
+  # Rendering Session Info
217
+  output$sessionInfo <- renderPrint({
218
+    sessionInfo()
219
+  })
220
+  
203 221
   tagList(
204 222
     downloadButton('downloadData', 'Download'),
205 223
     actionButton('closeSave','Save & Close')
... ...
@@ -1,5 +1,6 @@
1 1
 library(shiny)
2 2
 library(shinythemes)
3
+library(plotly)
3 4
 
4 5
 selectDataInput <- function(id) {
5 6
   # Create a namespace function using the provided id
... ...
@@ -68,12 +69,17 @@ mainDataInput <- function(id) {
68 69
   ns <- NS(id)
69 70
   
70 71
   #UI Definition
71
-  mainPanel(width = 6,
72
-            ## h2("GSVA: gene set variation analysis"),
73
-            textOutput("information"),
74
-            plotOutput("plot"),
75
-            tableOutput("result"),
76
-            uiOutput("download"))
72
+  mainPanel( width = 6,
73
+            tabsetPanel(type="tabs",
74
+                        tabPanel("Graphics",
75
+                                 textOutput("information"),
76
+                                 plotlyOutput("plot"),
77
+                                 tableOutput("result"),
78
+                                 uiOutput("download")),
79
+                        tabPanel("Session Info",
80
+                                 verbatimTextOutput("sessionInfo"))
81
+                                 )
82
+            )
77 83
 }
78 84
 
79 85
 argumentsDataInput <- function(id) {
... ...
@@ -130,10 +136,7 @@ fluidPage(
130 136
              windowTitle="GSVA"),
131 137
 	fluidRow(
132 138
 	  selectDataInput("dataInput"),
133
-	  mainDataInput("mainInput")
134
-	  ,
135
-	  fluidRow(
136
-	    argumentsDataInput("argumentsInput")
137
-	  )
139
+	  mainDataInput("mainInput"),
140
+	  argumentsDataInput("argumentsInput")
138 141
 	)
139 142
 )