Browse code

Added new ecdf plot

pablo-rodr-bio2 authored on 03/06/2020 10:12:49
Showing2 changed files

... ...
@@ -196,21 +196,44 @@ gsva_information <- function(input, output, session) {
196 196
     gsva_es <- as.data.frame(assays(generated_gsva)[[1]])
197 197
   else
198 198
     stop("Unknown output generated by the call to the 'gsva()' function.")
199
+
200
+  #Rendering text
201
+  output$text1 <- renderUI({
202
+    HTML(paste("<br/>", "\t To see the Empirical Cumulative Distribution Function 
203
+    of a Sample, click on its line in this plot and go
204
+      to the 'Gene.Set' Panel", "<br/>", sep="<br/>"))
205
+  })
206
+  
207
+  # Rendering graph1
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", source = "click")
214
+  })
199 215
   
200 216
   # Rendering table
201 217
   resultInformation <- matrix(data = c(nrow(generated_gsva),
202 218
                                        ncol(generated_gsva)),
203
-                                       nrow = 1, ncol = 2)
219
+                              nrow = 1, ncol = 2)
204 220
   colnames(resultInformation) <- c("Nr. of gene sets", "Nr. of samples")
205 221
   output$result <- renderTable(resultInformation)
206 222
   
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")
223
+  #Rendering graph2
224
+  eventData <- reactive({
225
+    event_data("plotly_click", source = "click")
226
+  })
227
+  output$plot2 <- renderPlotly({
228
+    req(eventData())
229
+    ind <- eventData()$curveNumber+1
230
+    subind <- colnames(generated_gsva)[ind]
231
+    p <- ggplot(data = dat.t[Sample==subind], aes(x=value, color=Sample)) +
232
+      stat_ecdf(geom="point") + 
233
+      theme(legend.position = "none") + 
234
+      labs(x=paste0("GSVA Scores of ", subind), y="Empirical Cumulative Density")
235
+    p <- ggplotly(p)
236
+    style(p, text=row.names(generated_gsva))
214 237
   })
215 238
   
216 239
   # Rendering Session Info
... ...
@@ -71,11 +71,13 @@ mainDataInput <- function(id) {
71 71
   #UI Definition
72 72
   mainPanel( width = 6,
73 73
             tabsetPanel(type="tabs",
74
-                        tabPanel("Graphics",
75
-                                 textOutput("information"),
74
+                        tabPanel("Samples",
75
+                                 htmlOutput("text1"),
76 76
                                  plotlyOutput("plot"),
77 77
                                  tableOutput("result"),
78 78
                                  uiOutput("download")),
79
+                        tabPanel("Gene Sets",
80
+                                 plotlyOutput("plot2")),
79 81
                         tabPanel("Session Info",
80 82
                                  verbatimTextOutput("sessionInfo"))
81 83
                                  )