Abstract

The package omXplore is able to embed third party plots. This vignette aims to explain how to add an external plot to the main UI of omXplore.

Introduction

An interesting feature about omXplore is the capacity to insert custom plots into the collection of vignettes of the Shiny app view_dataset(). This is useful to complete the panel of built-in plots of omXplore and the main UI (See ?view_dataset).

This vignette aims to describe how to (i) develop a plot function compliant with omXplore and (ii) add a new plot in the main app of the package omXplore.

Develop a plot module for omXplore

Any plot function, to be compatible with omXplore, must be written as a shiny module to allow for better code organisation and re-usability. Let suppose one wants to write a plot called “myFirstPlot”. As usual, the code of this shiny app is divided into two parts:

  • User interface (UI): function “myFirstPlot_ui()”
  • Server: function “myFirstPlot_server()”

Moreover, the parameters of these two functions must have the same name and class as the built-in plot functions in omXplore . For more details, see ?extFoo1 which is a simple example of what a generic plot function should looks like.

Following Bioconductor’s recommendations about Running shiny apps, the source code for this plot function should look as follows:

myFirstPlot <- function(obj, i) {
  ui <- myFirstPlot_ui(id)
  server <- myFirstPlot_server(id, obj, i)
  app <- shinyApp(ui = ui, server = server)
}

These three functions (myFirstPlot_ui(), myFirstPlot_server() and myFirstPlot()) can be written in the same source file (e.g. myFirstPlot.R)

Adding an existing module

From a R package

When one wants to add an external plot from a R package, it is by means of the parameter ‘addons’ of the function view_dataset(). This parameter is a list structured as follows:

  • the name of each slot is the name of a R package in which a plot module is implemented,

  • the content of the slot is a vector of modules names.

It is necessary that the functions *_ui() and *_server are defined outside the global app function myFirstPlot(). This is because the function “view_dataset” cannot use the function myFirstPlot() and it must use the two functions myFirstPlot_ui(), myFirstPlot_server().

Thus, the following code will not work:

myFirstPlot <- function(obj, i) {
  ui <- function(id) {
  ...
  }
  server <- function(id, obj, i) {
  moduleServer(id, 
    function(input, output, session) {
    ...
  })
  }
  
  app <- shinyApp(ui = ui, server = server)
}

A functional code is as follows:

myFirstPlot_ui <- function(id) {
  ...
}


myFirstPlot_server <- function(id, obj, i) {
  moduleServer(id, 
    function(input, output, session) {
    ...
  })
}

myFirstPlot <- function(obj, i) {
  ui <- myFirstPlot_ui(id)
  server <- myFirstPlot_server(id, obj, i)
  app <- shinyApp(ui = ui, server = server)
}

As an example, the code below will add three external plots:

  • package myPkgA: the plot functions “extFoo1” and “extFoo2”,

  • package myPkgB: the plot function “extFoo1”.

The corresponding R code is the following:

addons <- list(
  myPkgA = c("extFoo1", "extFoo2"),
  myPkgB = c("extFoo1")
  )
view_dataset(myData, addons)

Functions can have same names if they are part of different packages.

With this procedure, it is not necessary to load the entire package in order to user the plot module. omXplore loads only the necessary code for the plot fucntions.

Icon for clickable vignette

If the plot function is part of a R package, it is possible to store a *.png image that serves as icon for the clickable vignette displayed in the (B) area of the main app of omXplore. For that purpose, the file should be stored in the ‘images’ directory of the corresponding package and its name should be the same as the function it refers to.

The global file structure for the plot function of the example is the following:

MyPackage/
|-- R/
|   |-- myFirstPlot.R
|-- inst/
|   |-- images/
|       |-- myFirstPlot.png

From R console

If the plot function is written in a R script nor console, the same rules are used to write the three functions described in the previous section.

However, there are two important modifications:

  • the name of the three functions must be prefixed by “omXplore_’

  • so as to let omXplore find the plot function, it must already be loaded in the global R environment before running the app view_dataset(). Please note that in this case, there is to need to set the parameter “addons”.

omXplore_mySecondPlot <- function(obj, i) {
  ui <- omXplore_mySecondPlot_ui(id)
  server <- omXplore_mySecondPlot_server(id, obj, i)
  app <- shinyApp(ui = ui, server = server)
}

Session information

## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.5 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## time zone: UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] omXplore_0.99.92 BiocStyle_2.32.1
## 
## loaded via a namespace (and not attached):
##   [1] RColorBrewer_1.1-3          jsonlite_1.8.9             
##   [3] MultiAssayExperiment_1.30.3 magrittr_2.0.3             
##   [5] shinyjqui_0.4.1             estimability_1.5.1         
##   [7] MALDIquant_1.22.3           rmarkdown_2.28             
##   [9] fs_1.6.4                    zlibbioc_1.50.0            
##  [11] ragg_1.3.3                  vctrs_0.6.5                
##  [13] htmltools_0.5.8.1           S4Arrays_1.4.1             
##  [15] curl_5.2.3                  broom_1.0.7                
##  [17] SparseArray_1.4.8           mzID_1.42.0                
##  [19] TTR_0.24.4                  sass_0.4.9                 
##  [21] KernSmooth_2.23-24          bslib_0.8.0                
##  [23] htmlwidgets_1.6.4           desc_1.4.3                 
##  [25] plyr_1.8.9                  impute_1.78.0              
##  [27] emmeans_1.10.5              zoo_1.8-12                 
##  [29] lubridate_1.9.3             cachem_1.1.0               
##  [31] igraph_2.0.3                mime_0.12                  
##  [33] iterators_1.0.14            lifecycle_1.0.4            
##  [35] pkgconfig_2.0.3             Matrix_1.7-0               
##  [37] R6_2.5.1                    fastmap_1.2.0              
##  [39] shiny_1.9.1                 GenomeInfoDbData_1.2.12    
##  [41] MatrixGenerics_1.16.0       clue_0.3-65                
##  [43] digest_0.6.37               pcaMethods_1.96.0          
##  [45] colorspace_2.1-1            S4Vectors_0.42.1           
##  [47] textshaping_0.4.0           GenomicRanges_1.56.2       
##  [49] fansi_1.0.6                 timechange_0.3.0           
##  [51] httr_1.4.7                  abind_1.4-8                
##  [53] compiler_4.4.1              doParallel_1.0.17          
##  [55] backports_1.5.0             BiocParallel_1.38.0        
##  [57] viridis_0.6.5               dendextend_1.18.1          
##  [59] gplots_3.2.0                MASS_7.3-60.2              
##  [61] DelayedArray_0.30.1         scatterplot3d_0.3-44       
##  [63] gtools_3.9.5                caTools_1.18.3             
##  [65] mzR_2.38.0                  flashClust_1.01-2          
##  [67] tools_4.4.1                 PSMatch_1.8.0              
##  [69] httpuv_1.6.15               quantmod_0.4.26            
##  [71] FactoMineR_2.11             glue_1.8.0                 
##  [73] promises_1.3.0              QFeatures_1.14.2           
##  [75] grid_4.4.1                  reshape2_1.4.4             
##  [77] cluster_2.1.6               generics_0.1.3             
##  [79] gtable_0.3.5                preprocessCore_1.66.0      
##  [81] shinyBS_0.61.1              sm_2.2-6.0                 
##  [83] tidyr_1.3.1                 data.table_1.16.2          
##  [85] utf8_1.2.4                  XVector_0.44.0             
##  [87] BiocGenerics_0.50.0         foreach_1.5.2              
##  [89] ggrepel_0.9.6               pillar_1.9.0               
##  [91] stringr_1.5.1               limma_3.60.6               
##  [93] later_1.3.2                 dplyr_1.1.4                
##  [95] lattice_0.22-6              tidyselect_1.2.1           
##  [97] vioplot_0.5.0               knitr_1.48                 
##  [99] gridExtra_2.3               bookdown_0.41              
## [101] IRanges_2.38.1              ProtGenerics_1.36.0        
## [103] SummarizedExperiment_1.34.0 stats4_4.4.1               
## [105] xfun_0.48                   Biobase_2.64.0             
## [107] statmod_1.5.0               factoextra_1.0.7           
## [109] MSnbase_2.30.1              matrixStats_1.4.1          
## [111] DT_0.33                     visNetwork_2.1.2           
## [113] stringi_1.8.4               UCSC.utils_1.0.0           
## [115] lazyeval_0.2.2              yaml_2.3.10                
## [117] evaluate_1.0.1              codetools_0.2-20           
## [119] MsCoreUtils_1.16.1          tibble_3.2.1               
## [121] BiocManager_1.30.25         affyio_1.74.0              
## [123] multcompView_0.1-10         cli_3.6.3                  
## [125] xtable_1.8-4                systemfonts_1.1.0          
## [127] munsell_0.5.1               jquerylib_0.1.4            
## [129] Rcpp_1.0.13                 GenomeInfoDb_1.40.1        
## [131] XML_3.99-0.17               parallel_4.4.1             
## [133] leaps_3.2                   pkgdown_2.1.1              
## [135] ggplot2_3.5.1               assertthat_0.2.1           
## [137] AnnotationFilter_1.28.0     bitops_1.0-9               
## [139] viridisLite_0.4.2           mvtnorm_1.3-1              
## [141] rlist_0.4.6.2               affy_1.82.0                
## [143] scales_1.3.0                xts_0.14.1                 
## [145] ncdf4_1.23                  purrr_1.0.2                
## [147] highcharter_0.9.4           crayon_1.5.3               
## [149] rlang_1.1.4                 vsn_3.72.0                 
## [151] shinyjs_2.1.0