# Adding third party plots

Samuel Wieczorek and Thomas Burger

#### 2025-06-04

#### 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`.

#### Package

omXplore 1.3.0

# 1 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`.

# 2 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)

# 3 Adding an existing module

## 3.1 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

## 3.2 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)
    }

## 3.3 Session information

    sessionInfo()

    ## R version 4.5.0 (2025-04-11 ucrt)
    ## Platform: x86_64-w64-mingw32/x64
    ## Running under: Windows Server 2022 x64 (build 20348)
    ##
    ## Matrix products: default
    ##   LAPACK version 3.12.1
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.utf8
    ## [3] LC_MONETARY=English_United States.utf8
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.utf8
    ##
    ## time zone: America/New_York
    ## tzcode source: internal
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] omXplore_1.3.0   BiocStyle_2.37.0
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] splines_4.5.0               later_1.4.2
    ##   [3] bitops_1.0-9                tibble_3.2.1
    ##   [5] preprocessCore_1.71.0       xts_0.14.1
    ##   [7] XML_3.99-0.18               factoextra_1.0.7
    ##   [9] lifecycle_1.0.4             shinyjqui_0.4.1
    ##  [11] doParallel_1.0.17           lattice_0.22-7
    ##  [13] MASS_7.3-65                 flashClust_1.01-2
    ##  [15] MultiAssayExperiment_1.35.3 dendextend_1.19.0
    ##  [17] backports_1.5.0             magrittr_2.0.3
    ##  [19] limma_3.65.1                sass_0.4.10
    ##  [21] rmarkdown_2.29              jquerylib_0.1.4
    ##  [23] yaml_2.3.10                 rlist_0.4.6.2
    ##  [25] sm_2.2-6.0                  shinyBS_0.61.1
    ##  [27] httpuv_1.6.16               MsCoreUtils_1.21.0
    ##  [29] RColorBrewer_1.1-3          lubridate_1.9.4
    ##  [31] multcomp_1.4-28             abind_1.4-8
    ##  [33] GenomicRanges_1.61.0        purrr_1.0.4
    ##  [35] AnnotationFilter_1.33.0     BiocGenerics_0.55.0
    ##  [37] TH.data_1.1-3               sandwich_3.1-1
    ##  [39] IRanges_2.43.0              S4Vectors_0.47.0
    ##  [41] ggrepel_0.9.6               MSnbase_2.35.0
    ##  [43] highcharter_0.9.4           ncdf4_1.24
    ##  [45] codetools_0.2-20            DelayedArray_0.35.1
    ##  [47] DT_0.33                     bs4Dash_2.3.4
    ##  [49] tidyselect_1.2.1            Spectra_1.19.2
    ##  [51] UCSC.utils_1.5.0            farver_2.1.2
    ##  [53] viridis_0.6.5               matrixStats_1.5.0
    ##  [55] stats4_4.5.0                showtext_0.9-7
    ##  [57] nipals_1.0                  jsonlite_2.0.0
    ##  [59] vioplot_0.5.1               waiter_0.2.5
    ##  [61] survival_3.8-3              iterators_1.0.14
    ##  [63] emmeans_1.11.1              foreach_1.5.2
    ##  [65] tools_4.5.0                 Rcpp_1.0.14
    ##  [67] glue_1.8.0                  gridExtra_2.3
    ##  [69] SparseArray_1.9.0           BiocBaseUtils_1.11.0
    ##  [71] xfun_0.52                   MatrixGenerics_1.21.0
    ##  [73] TTR_0.24.4                  GenomeInfoDb_1.45.4
    ##  [75] dplyr_1.1.4                 BiocManager_1.30.25
    ##  [77] fastmap_1.2.0               shinyjs_2.1.0
    ##  [79] caTools_1.18.3              digest_0.6.37
    ##  [81] timechange_0.3.0            R6_2.6.1
    ##  [83] mime_0.13                   estimability_1.5.1
    ##  [85] gtools_3.9.5                dichromat_2.0-0.1
    ##  [87] tidyr_1.3.1                 generics_0.1.4
    ##  [89] data.table_1.17.4           PSMatch_1.13.1
    ##  [91] httr_1.4.7                  htmlwidgets_1.6.4
    ##  [93] S4Arrays_1.9.1              scatterplot3d_0.3-44
    ##  [95] pkgconfig_2.0.3             gtable_0.3.6
    ##  [97] impute_1.83.0               XVector_0.49.0
    ##  [99] htmltools_0.5.8.1           sysfonts_0.8.9
    ## [101] bookdown_0.43               MALDIquant_1.22.3
    ## [103] multcompView_0.1-10         ProtGenerics_1.41.0
    ## [105] clue_0.3-66                 scales_1.4.0
    ## [107] Biobase_2.69.0              leaps_3.2
    ## [109] knitr_1.50                  MetaboCoreUtils_1.17.1
    ## [111] rstudioapi_0.17.1           reshape2_1.4.4
    ## [113] coda_0.19-4.1               visNetwork_2.1.2
    ## [115] curl_6.2.3                  showtextdb_3.0
    ## [117] cachem_1.1.0                zoo_1.8-14
    ## [119] stringr_1.5.1               KernSmooth_2.23-26
    ## [121] parallel_4.5.0              mzID_1.47.0
    ## [123] vsn_3.77.0                  pillar_1.10.2
    ## [125] grid_4.5.0                  vctrs_0.6.5
    ## [127] gplots_3.2.0                pcaMethods_2.1.0
    ## [129] promises_1.3.3              xtable_1.8-4
    ## [131] cluster_2.1.8.1             evaluate_1.0.3
    ## [133] mvtnorm_1.3-3               cli_3.6.5
    ## [135] compiler_4.5.0              rlang_1.1.6
    ## [137] crayon_1.5.3                QFeatures_1.19.2
    ## [139] affy_1.87.0                 plyr_1.8.9
    ## [141] fs_1.6.6                    stringi_1.8.7
    ## [143] viridisLite_0.4.2           BiocParallel_1.43.3
    ## [145] assertthat_0.2.1            lazyeval_0.2.2
    ## [147] Matrix_1.7-3                ggplot2_3.5.2
    ## [149] statmod_1.5.0               FactoMineR_2.11
    ## [151] shiny_1.10.0                SummarizedExperiment_1.39.0
    ## [153] mzR_2.43.0                  igraph_2.1.4
    ## [155] broom_1.0.8                 affyio_1.79.0
    ## [157] bslib_0.9.0                 thematic_0.1.6
    ## [159] quantmod_0.4.27