Browse code

shiny and miniUI in Suggests:

Davide Risso authored on 30/06/2017 21:29:49
Showing 4 changed files

... ...
@@ -37,8 +37,6 @@ Imports:
37 37
   mixtools,
38 38
   RColorBrewer,
39 39
   boot,
40
-  shiny,
41
-  miniUI,
42 40
   rhdf5,
43 41
   RUVSeq,
44 42
   DT,
... ...
@@ -50,9 +48,11 @@ Imports:
50 48
   rARPACK
51 49
 Suggests:
52 50
   BiocStyle,
53
-  scRNAseq,
54 51
   knitr,
52
+  miniUI,
55 53
   rmarkdown,
54
+  scRNAseq,
55
+  shiny,
56 56
   testthat
57 57
 VignetteBuilder: knitr
58 58
 LazyLoad: yes
... ...
@@ -93,9 +93,6 @@ importFrom(limma,lmFit)
93 93
 importFrom(matrixStats,colIQRs)
94 94
 importFrom(matrixStats,colMedians)
95 95
 importFrom(matrixStats,rowMedians)
96
-importFrom(miniUI,gadgetTitleBar)
97
-importFrom(miniUI,miniContentPanel)
98
-importFrom(miniUI,miniPage)
99 96
 importFrom(mixtools,normalmixEM)
100 97
 importFrom(rARPACK,svds)
101 98
 importFrom(reshape2,melt)
... ...
@@ -107,7 +104,6 @@ importFrom(rhdf5,h5write)
107 104
 importFrom(rhdf5,h5write.default)
108 105
 importFrom(scran,computeSumFactors)
109 106
 importFrom(shiny,br)
110
-importFrom(shiny,brushedPoints)
111 107
 importFrom(shiny,column)
112 108
 importFrom(shiny,downloadHandler)
113 109
 importFrom(shiny,downloadLink)
... ...
@@ -123,20 +119,16 @@ importFrom(shiny,plotOutput)
123 119
 importFrom(shiny,reactive)
124 120
 importFrom(shiny,renderPlot)
125 121
 importFrom(shiny,renderTable)
126
-importFrom(shiny,renderText)
127
-importFrom(shiny,runGadget)
128 122
 importFrom(shiny,selectInput)
129 123
 importFrom(shiny,shinyApp)
130 124
 importFrom(shiny,sidebarLayout)
131 125
 importFrom(shiny,sidebarPanel)
132 126
 importFrom(shiny,sliderInput)
133
-importFrom(shiny,stopApp)
134 127
 importFrom(shiny,tabPanel)
135 128
 importFrom(shiny,tableOutput)
136 129
 importFrom(shiny,tabsetPanel)
137 130
 importFrom(shiny,titlePanel)
138 131
 importFrom(shiny,updateSelectInput)
139
-importFrom(shiny,verbatimTextOutput)
140 132
 importFrom(stats,approx)
141 133
 importFrom(stats,as.formula)
142 134
 importFrom(stats,binomial)
... ...
@@ -1,24 +1,20 @@
1 1
 #' Interactive biplot
2
-#' 
2
+#'
3 3
 #' This is a wrapper around \code{\link{biplot_color}}, creating a shiny gadget
4 4
 #' to allow the user to select specific points in the graph.
5
-#' 
5
+#'
6 6
 #' @details Since this is based on the shiny gadget feature, it will not work
7 7
 #'   in static documents, such as vignettes or markdown / knitr documents. See
8 8
 #'   \code{biplot_color} for more details on the internals.
9
-#'   
9
+#'
10 10
 #' @param x a \code{\link{SconeExperiment}} object.
11 11
 #' @param ... passed to \code{\link{biplot_color}}.
12
-#'   
13
-#' @importFrom miniUI gadgetTitleBar miniContentPanel miniPage gadgetTitleBar
14
-#' @importFrom shiny plotOutput renderPlot observeEvent brushedPoints runGadget
15
-#'   verbatimTextOutput stopApp renderText
16
-#'   
12
+#'
17 13
 #' @export
18
-#' 
19
-#' @return A \code{\link{SconeExperiment}} object representing 
14
+#'
15
+#' @return A \code{\link{SconeExperiment}} object representing
20 16
 #'   selected methods.
21
-#'   
17
+#'
22 18
 #' @examples
23 19
 #' mat <- matrix(rpois(1000, lambda = 5), ncol=10)
24 20
 #' colnames(mat) <- paste("X", 1:ncol(mat), sep="")
... ...
@@ -30,19 +26,27 @@
30 26
 #' \dontrun{
31 27
 #' biplot_interactive(res)
32 28
 #' }
33
-#' 
29
+#'
34 30
 biplot_interactive <- function(x, ...) {
35 31
 
32
+  if (!requireNamespace("shiny", quietly = TRUE)) {
33
+    stop("shiny package needed for biplot_interactive")
34
+  }
35
+
36
+  if (!requireNamespace("miniUI", quietly = TRUE)) {
37
+    stop("miniUI package needed for biplot_interactive")
38
+  }
39
+
36 40
   data <- as.data.frame(apply(t(get_scores(x)),1,rank))
37 41
   scores <- get_score_ranks(x)
38 42
 
39
-  ui <- miniPage(
40
-    gadgetTitleBar("Drag to select points"),
41
-    miniContentPanel(
43
+  ui <- miniUI::miniPage(
44
+    miniUI::gadgetTitleBar("Drag to select points"),
45
+    miniUI::miniContentPanel(
42 46
       # The brush="brush" argument means we can listen for
43 47
       # brush events on the plot using input$brush.
44
-      plotOutput("plot1", height = "80%", brush = "plot_brush"),
45
-      verbatimTextOutput("info")
48
+      shiny::plotOutput("plot1", height = "80%", brush = "plot_brush"),
49
+      shiny::verbatimTextOutput("info")
46 50
     )
47 51
   )
48 52
 
... ...
@@ -53,14 +57,14 @@ biplot_interactive <- function(x, ...) {
53 57
     bp_obj <- biplot_color(pc_obj, y = scores)
54 58
 
55 59
     # Render the plot
56
-    output$plot1 <- renderPlot({
60
+    output$plot1 <- shiny::renderPlot({
57 61
       # Biplot
58 62
       biplot_color(pc_obj, y = scores, ...)
59 63
     })
60 64
 
61 65
     data_out <- cbind(data, bp_obj)
62 66
 
63
-    output$info <- renderText({
67
+    output$info <- shiny::renderText({
64 68
       xy_range_str <- function(e) {
65 69
         if(is.null(e)) return("NULL\n")
66 70
         idx <- which(bp_obj[,1] >= e$xmin & bp_obj[,1] <= e$xmax &
... ...
@@ -71,16 +75,16 @@ biplot_interactive <- function(x, ...) {
71 75
     })
72 76
 
73 77
     # Handle the Done button being pressed.
74
-    observeEvent(input$done, {
78
+    shiny::observeEvent(input$done, {
75 79
       # Return the brushed points. See ?shiny::brushedPoints.
76
-      names <- rownames(brushedPoints(data_out, 
77
-                                      input$plot_brush, 
80
+      names <- rownames(shiny::brushedPoints(data_out,
81
+                                      input$plot_brush,
78 82
                                       xvar="PC1",
79 83
                                       yvar="PC2"))
80 84
       out <- select_methods(x, names)
81
-      stopApp(invisible(out))
85
+      shiny::stopApp(invisible(out))
82 86
     })
83 87
   }
84 88
 
85
-  runGadget(ui, server)
89
+  shiny::runGadget(ui, server)
86 90
 }
... ...
@@ -12,7 +12,7 @@ biplot_interactive(x, ...)
12 12
 \item{...}{passed to \code{\link{biplot_color}}.}
13 13
 }
14 14
 \value{
15
-A \code{\link{SconeExperiment}} object representing 
15
+A \code{\link{SconeExperiment}} object representing
16 16
   selected methods.
17 17
 }
18 18
 \description{