library(ComplexHeatmap) library(InteractiveComplexHeatmap)
m = matrix(rnorm(100), 10) ht = draw(Heatmap(m))
ui = fluidPage( actionButton("show_heatmap", "Make me interactive"), ) server = function(input, output, session) { observeEvent(input$show_heatmap, { InteractiveComplexHeatmapModal(input, output, session, ht) }) } shiny::shinyApp(ui, server)
ui = fluidPage( radioButtons("select", "Select", c("Numeric" = 1, "Character" = 2)), actionButton("show_heatmap", "Generate_heatmap"), htmlOutput("heatmap_output") ) get_heatmap_fun = function(i) { mat_list = list( matrix(rnorm(100), 10), matrix(sample(letters[1:10], 100, replace = TRUE), 10) ) Heatmap(mat_list[[i]]) } server = function(input, output, session) { observeEvent(input$show_heatmap, { i = as.numeric(input$select) InteractiveComplexHeatmapWidget(input, output, session, ht_list = get_heatmap_fun(i), output_id = "heatmap_output") }) } shiny::shinyApp(ui, server)
The source code of this R Markdown document is:
---
title: "InteractiveComplexHeatmap in an Rmarkdown document"
author: "Zuguang Gu"
date: "16/12/2020"
output: html_document
runtime: shiny
---
`r ''````r
library(ComplexHeatmap)
library(InteractiveComplexHeatmap)
```
## Use InteractiveComplexHeatmapModal()
`r ''````r
m = matrix(rnorm(100), 10)
ht = draw(Heatmap(m))
```
`r ''````r
ui = fluidPage(
actionButton("show_heatmap", "Make me interactive"),
)
server = function(input, output, session) {
m = matrix(rnorm(100), 10)
ht = Heatmap(m)
observeEvent(input$show_heatmap, {
InteractiveComplexHeatmapModal(input, output, session, ht)
})
}
shiny::shinyApp(ui, server)
```
## Use InteractiveComplexHeatmapWidget()
`r ''````r
ui = fluidPage(
radioButtons("select", "Select", c("Numeric" = 1, "Character" = 2)),
actionButton("show_heatmap", "Generate_heatmap"),
)
get_heatmap_fun = function(i) {
mat_list = list(
matrix(rnorm(100), 10),
matrix(sample(letters[1:10], 100, replace = TRUE), 10)
)
Heatmap(mat_list[[i]])
}
server = function(input, output, session) {
observeEvent(input$show_heatmap, {
i = as.numeric(input$select)
InteractiveComplexHeatmapWidget(input, output, session,
ht_list = get_heatmap_fun(i), output_id = "heatmap_output")
})
}
shiny::shinyApp(ui, server)
```
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.