Browse code

Interactive Graph changes

vasumathi298 authored on 09/08/2023 06:33:38
Showing 4 changed files

... ...
@@ -23,7 +23,7 @@ Authors@R: c(
23 23
     person("Olga", "Vitek", email = "[email protected]", role = "aut"))
24 24
 License: Artistic-2.0
25 25
 Depends: R (>= 4.2)
26
-Imports: shiny, shinyBS, shinyjs, shinybusy, dplyr, ggplot2, data.table, Hmisc,
26
+Imports: shiny, shinyBS, shinyjs, shinybusy, dplyr, ggplot2,plotly, data.table, Hmisc,
27 27
   MSstats, MSstatsTMT, MSstatsPTM, MSstatsConvert, gplots, marray, DT, readxl,
28 28
   ggrepel, uuid, utils, stats, htmltools, methods, tidyr, grDevices, graphics
29 29
 Suggests: 
... ...
@@ -15,6 +15,10 @@ import(MSstatsConvert)
15 15
 import(MSstatsTMT)
16 16
 import(data.table)
17 17
 import(ggplot2)
18
+importFrom(plotly,plot_ly)
19
+importFrom(plotly,ggplotly)
20
+importFrom(plotly,plotlyOutput)
21
+importFrom(plotly,renderPlotly)
18 22
 importFrom(DT,dataTableOutput)
19 23
 importFrom(DT,renderDataTable)
20 24
 importFrom(Hmisc,describe)
... ...
@@ -436,6 +436,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
436 436
                                                             savePDF=pdf)
437 437
       }, error = function(e){
438 438
         remove_modal_spinner()
439
+        message("An error occurred: ", conditionMessage(e))
439 440
         stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
440 441
       )
441 442
     }
... ...
@@ -677,7 +678,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
677 678
     insertUI(
678 679
       selector = paste0("#", ns("comparison_plots")),
679 680
       ui=tags$div(
680
-        plotOutput(ns("comp_plots"), height = "100%", click = "click1"),
681
+        plotlyOutput(ns("comp_plots"), height = "100%"),
681 682
         conditionalPanel(condition = "input['statmodel-typeplot'] == 'VolcanoPlot' && input['loadpage-DDA_DIA']!='TMT'",
682 683
                          h5("Click on plot for details"),
683 684
                          verbatimTextOutput(ns("info2"))),
... ...
@@ -688,8 +689,9 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
688 689
   }
689 690
   )
690 691
   
691
-  observe({output$comp_plots = renderPlot({
692
-    group_comparison(FALSE, FALSE)}, height = input$height
692
+  observe({output$comp_plots = renderPlotly({
693
+    group_comparison(FALSE, FALSE)
694
+    }
693 695
   )
694 696
   })
695 697
 
... ...
@@ -847,6 +849,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
847 849
     }
848 850
   )
849 851
 
852
+  
850 853
   output$plotresults = downloadHandler(
851 854
     filename = function() {
852 855
       paste("SummaryPlot-", Sys.Date(), ".pdf", sep="")
... ...
@@ -118,58 +118,58 @@ groupComparisonPlots2 = function(data=data,
118 118
   allfiles = list.files()
119 119
   filenaming = "msstats"
120 120
   if (length(grep(filenaming,allfiles)) == 0) {
121
-
121
+    
122 122
     finalfile = "msstats.log"
123 123
     processout = NULL
124
-
124
+    
125 125
   } else {
126
-
126
+    
127 127
     num = 0
128 128
     finalfile = "msstats.log"
129
-
129
+    
130 130
     while(is.element(finalfile, allfiles)) {
131 131
       num = num + 1
132 132
       lastfilename = finalfile ## in order to rea
133 133
       finalfile = paste(paste(filenaming, num, sep="-"), ".log", sep="")
134 134
     }
135
-
135
+    
136 136
     finalfile = lastfilename
137 137
     processout = as.matrix(read.table(finalfile, header=TRUE, sep="\t"))
138 138
   }
139
-
139
+  
140 140
   processout = rbind(processout, as.matrix(c(" ", " ", "MSstats - groupComparisonPlots function", " "), ncol=1))
141
-
141
+  
142 142
   ## make upper letter
143 143
   type = toupper(type)
144
-
144
+  
145 145
   if (length(setdiff(type, c("HEATMAP", "VOLCANOPLOT", "COMPARISONPLOT"))) != 0) {
146
-
146
+    
147 147
     processout = rbind(processout, c(paste("Input for type=", type, ". However,'type' should be one of \"Heatmap\", \"VolcanoPlot\",\"ComparisonPlot\".", sep="")))
148 148
     write.table(processout, file=finalfile, row.names=FALSE)
149
-
149
+    
150 150
     stop(paste("Input for type=", type, ". However,'type' should be one of \"Heatmap\", \"VolcanoPlot\",\"ComparisonPlot\".", sep=""))
151 151
   }
152
-
152
+  
153 153
   ## check logBase.pvalue is 2,10 or not
154 154
   if (logBase.pvalue != 2 & logBase.pvalue != 10) {
155 155
     processout = rbind(processout, c("ERROR : (-) Logarithm transformation for adjusted p-values : log2 or log10 only - stop"))
156 156
     write.table(processout, file=finalfile, row.names=FALSE)
157
-
157
+    
158 158
     stop("Only -log2 or -log10 for logarithm transformation for adjusted p-values are posssible.\n")
159 159
   }
160
-
160
+  
161 161
   if (which.Comparison != "all") {
162 162
     ## check which.comparison is name of comparison
163 163
     if (is.character(which.Comparison)) {
164
-
164
+      
165 165
       temp.name = which.Comparison
166
-
166
+      
167 167
       ## message if name of comparison is wrong.
168 168
       if (length(setdiff(temp.name, unique(data$Label))) > 0) {
169
-
169
+        
170 170
         processout = rbind(processout, paste("Please check labels of comparions. Result does not have this comparison. -", paste(temp.name, collapse=", "), sep=" "))
171 171
         write.table(processout, file=finalfile, row.names=FALSE)
172
-
172
+        
173 173
         stop(paste("Please check labels of comparions. Result does not have this comparison. -", paste(temp.name, collapse=", "), sep=" "))
174 174
       }
175 175
     }
... ...
@@ -399,7 +399,7 @@ groupComparisonPlots2 = function(data=data,
399 399
         }
400 400
       } else if ( length(which.Comparison) > 1 ) {
401 401
         stop( '** Cannnot generate multiple volcano plots in a screen. Please set one comparison at a time.' )
402
-
402
+        
403 403
       }
404 404
     }
405 405
     
... ...
@@ -761,9 +761,9 @@ groupComparisonPlots2 = function(data=data,
761 761
         print(ptemp)
762 762
       }
763 763
       else {
764
-        return(ptemp)
764
+        return(ggplotly(ptemp))
765 765
       }
766
-
766
+      
767 767
     } ## end-loop
768 768
     
769 769
     # if (address!=FALSE) {
... ...
@@ -788,7 +788,7 @@ groupComparisonPlots2 = function(data=data,
788 788
         stop( '** Cannnot generate multiple comparison plots in a screen. Please set one protein at a time.' )
789 789
       }
790 790
     }
791
-
791
+    
792 792
     ## choose Proteins or not
793 793
     if (which.Protein != "all") {
794 794
       ## check which.Protein is name of Protein
... ...
@@ -887,7 +887,7 @@ groupComparisonPlots2 = function(data=data,
887 887
         print(ptemp)
888 888
       }
889 889
       else {
890
-        return(ptemp)
890
+        return(ggplotly(ptemp))
891 891
       }
892 892
       
893 893
       message(paste("Drew compasison plot for ", unique(sub$PROTEIN), "(", i, " of ", length(unique(datatemp$Protein)), ")"))