Sections 1 and 2 are adapted from the original tutorial, while sections 3 and 4 are new examples that demonstrate how to integrate InteractiveComplexHeatmap into a Shiny module and a teal module, respectively. Each section includes the necessary code changes and explanations to help users understand how to implement the interactive heatmap in different contexts.
Prerequisites
library(shiny)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
========================================
tidyHeatmap version 1.13.1
If you use tidyHeatmap in published research, please cite:
1) Mangiola et al. tidyHeatmap: an R package for modular heatmap production
based on tidy principles. JOSS 2020.
2) Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional
genomic data. Bioinformatics 2016.
This message can be suppressed by:
suppressPackageStartupMessages(library(tidyHeatmap))
========================================
Attaching package: 'tidyHeatmap'
The following object is masked from 'package:stats':
heatmap
========================================
ComplexHeatmap version 2.26.1
Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
Github page: https://github.com/jokergoo/ComplexHeatmap
Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
If you use it in published research, please cite either one:
- Gu, Z. Complex Heatmap Visualization. iMeta 2022.
- Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional
genomic data. Bioinformatics 2016.
The new InteractiveComplexHeatmap package can directly export static
complex heatmaps into an interactive Shiny app with zero effort. Have a try!
This message can be suppressed by:
suppressPackageStartupMessages(library(ComplexHeatmap))
========================================
library(InteractiveComplexHeatmap)
========================================
InteractiveComplexHeatmap version 1.9.2
Bioconductor page: http://bioconductor.org/packages/InteractiveComplexHeatmap/
Github page: https://github.com/jokergoo/InteractiveComplexHeatmap
If you use it in published research, please cite:
Gu, Z. Make Interactive Complex Heatmaps in R, 2021, Bioinformatics
This message can be suppressed by:
suppressPackageStartupMessages(library(InteractiveComplexHeatmap))
========================================
1. Hello World: InteractiveComplexHeatmap
Start with a static heatmap, then pass the drawn object to htShiny().
m <-matrix(rnorm(100*100), nrow =100)ht <- ComplexHeatmap::Heatmap(m)ComplexHeatmap::draw(ht)
InteractiveComplexHeatmap::htShiny(ht)
tidyHeatmap objects can be passed through as well.
tidyHeatmap says: (once per session) from release 1.7.0 the scaling is set to "none" by default. Please use scale = "row", "column" or "both" to apply scaling
tidyHeatmap says: If you use tidyHeatmap for scientific research, please cite: Mangiola, S. and Papenfuss, A.T., 2020. 'tidyHeatmap: an R package for modular heatmap production based on tidy principles.' Journal of Open Source Software. doi:10.21105/joss.02472.
This message is displayed once per session.
Warning: `when()` was deprecated in purrr 1.0.0.
ℹ Please use `if` instead.
ℹ The deprecated feature was likely used in the tidyHeatmap package.
Please report the issue at
<https://github.com/stemangiola/tidyHeatmap/issues>.
This step, also adapted from the InteractiveComplexHeatmap package, demonstrate a Shiny app, (without a shiny-module). Show the output in the UI and register the heatmap in the server.
Next, will modify the above into a Shiny module. Will do so via adding a namespace to the output id in both the UI and the server registration.
To adapt the standalone pattern into a Shiny module, the required code changes are:
Wrap the UI in a module UI function and create ns <- NS(id).
Replace the global output id with a namespaced id such as ns("ht_id") inside InteractiveComplexHeatmapOutput().
Wrap the server logic in moduleServer() and register the heatmap from inside the module server function.
Pass the same namespaced id to makeInteractiveComplexHeatmap(), typically as session$ns("ht_id"), so the output binding matches the module UI.
Instantiate the module from the outer app with a concrete id such as "some_id".
Note: For simplicity, the dataset is created inside the module (server part). Later on this will be relaxed, and dataset will be passed to the {main} app independently.
The teal framework leverage a collection of Shiny modules, that are are served together under a unified meta-UI layer.
A teal module bind the UI and Server together.
This example wraps the heatmap inside a teal module and lets the user choose from the available datasets. The input dataset is converted to a numeric matrix before constructing the heatmap.
To make the module function correctly inside teal, the required code changes are:
Define a module UI with teal.widgets::standard_layout() so the controls and output fit the expected teal layout.
Accept the data argument in the server function because teal::module() injects datasets through that interface.
Populate the dataset selector from names(data()) and react to input$dataset before building the heatmap.
Convert incoming data frames to a numeric matrix before calling ComplexHeatmap::Heatmap(). In this example, the ID column is moved into row names and the remaining values are coerced with as.matrix().
Pass the module through teal::module() and forward the datanames argument instead of hardcoding it, so callers can control which datasets are exposed.
Build the final app with init(data = ..., modules = modules(...)), then wrap the returned ui and server in shinyApp().