Title: | Make Interactive Complex Heatmaps |
---|---|
Description: | This package can easily make heatmaps which are produced by the ComplexHeatmap package into interactive applications. It provides two types of interactivities: 1. on the interactive graphics device, and 2. on a Shiny app. It also provides functions for integrating the interactive heatmap widgets for more complex Shiny app development. |
Authors: | Zuguang Gu [aut, cre] |
Maintainer: | Zuguang Gu <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.11.1 |
Built: | 2024-11-13 11:22:02 UTC |
Source: | https://github.com/jokergoo/InteractiveComplexHeatmap |
Get all column indicies from the selected data frame
all_column_indices(df)
all_column_indices(df)
df |
The selected data frame. |
# There is no example NULL
# There is no example NULL
Get all row indicies from the selected data frame
all_row_indices(df)
all_row_indices(df)
df |
The selected data frame. |
# There is no example NULL
# There is no example NULL
Get the position of the brushed area on the heatmap image
getPositionFromBrush(brush, ratio = 1)
getPositionFromBrush(brush, ratio = 1)
brush |
The input brush object. Assume |
ratio |
The relative resolution. The value should the ratio between |
A list of length two. The two elements correspons to the coordinates of the two diagonal points.
getPositionFromClick
, getPositionFromHover
, getPositionFromDblclick
.
# There is no example NULL
# There is no example NULL
Get the position of clicked point on the heatmap image
getPositionFromClick(click, ratio = 1)
getPositionFromClick(click, ratio = 1)
click |
The input click object. Assume |
ratio |
The relative resolution. The value should the ratio between |
A unit
object of length two which are the coordinates of the clicked points.
getPositionFromBrush
, getPositionFromHover
, getPositionFromDblclick
.
# There is no example NULL
# There is no example NULL
Get the position of double clicked point on the heatmap image
getPositionFromDblclick(dblclick, ratio = 1)
getPositionFromDblclick(dblclick, ratio = 1)
dblclick |
The input dblclick object. Assume |
ratio |
The relative resolution. The value should the ratio between |
A unit
object of length two which are the coordinates of the double clicked points.
# There is no example NULL
# There is no example NULL
Get the position of hovered point on the heatmap image
getPositionFromHover(hover, ratio = 1)
getPositionFromHover(hover, ratio = 1)
hover |
The input hover object. Assume |
ratio |
The relative resolution. The value should the ratio between |
A unit
object of length two which are the coordinates of the hover points.
# There is no example NULL
# There is no example NULL
UI for the output
HeatmapInfoOutput(heatmap_id, title = NULL, width = 400, output_ui = default_output_ui(heatmap_id), output_ui_float = FALSE, action = NULL, response = NULL, internal = FALSE)
HeatmapInfoOutput(heatmap_id, title = NULL, width = 400, output_ui = default_output_ui(heatmap_id), output_ui_float = FALSE, action = NULL, response = NULL, internal = FALSE)
heatmap_id |
ID of the plot. |
title |
Title of the output. |
width |
Width of the output div. |
output_ui |
A |
output_ui_float |
Whether the UI defined by |
action |
It is only used when |
response |
It is only used when |
internal |
Internally used. |
originalHeatmapOutput
, subHeatmapOutput
.
# See examples on the help page of originalHeatmapOutput()
# See examples on the help page of originalHeatmapOutput()
Interactive heatmaps as a Shiny app
ht_shiny(...)
ht_shiny(...)
... |
All goes to |
A Shiny app object.
# There is no example NULL
# There is no example NULL
Get heatmap positions on the graphics device
htPositionsOnDevice(ht_list = get_last_ht(), unit = "inch", valueOnly = FALSE, include_annotation = FALSE, calibrate = TRUE)
htPositionsOnDevice(ht_list = get_last_ht(), unit = "inch", valueOnly = FALSE, include_annotation = FALSE, calibrate = TRUE)
ht_list |
A |
unit |
The unit. |
valueOnly |
Whether only return the numeric values. |
include_annotation |
Internally used. |
calibrate |
Internally used. |
ht_list
must have been already updated by draw()
function. The function needs to be executed under a graphics device where the heatmap is written.
It returns a DataFrame
object of the position of every heatmap slice.
if(dev.interactive()) { m = matrix(rnorm(100), 10) ht = Heatmap(m, row_km = 2, column_km = 2) ht = draw(ht) pos = htPositionsOnDevice(ht) InteractiveComplexHeatmap:::redraw_ht_vp(pos) }
if(dev.interactive()) { m = matrix(rnorm(100), 10) ht = Heatmap(m, row_km = 2, column_km = 2) ht = draw(ht) pos = htPositionsOnDevice(ht) InteractiveComplexHeatmap:::redraw_ht_vp(pos) }
Interactive heatmaps as a Shiny app
htShiny(ht_list = get_last_ht(), title = NULL, description = NULL, hline = TRUE, html = NULL, # parameters passed to InteractiveComplexHeatmapOutput() heatmap_id = NULL, title1 = "Original heatmap", title2 = "Selected sub-heatmap", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 400, height2 = 350, width3 = ifelse(layout == "(1-2)|3", 800, 400), layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui_float = FALSE, # specific for sub-heatmap show_cell_fun = TRUE, show_layer_fun = TRUE, save = NULL, app_options = list())
htShiny(ht_list = get_last_ht(), title = NULL, description = NULL, hline = TRUE, html = NULL, # parameters passed to InteractiveComplexHeatmapOutput() heatmap_id = NULL, title1 = "Original heatmap", title2 = "Selected sub-heatmap", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 400, height2 = 350, width3 = ifelse(layout == "(1-2)|3", 800, 400), layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui_float = FALSE, # specific for sub-heatmap show_cell_fun = TRUE, show_layer_fun = TRUE, save = NULL, app_options = list())
ht_list |
A |
title |
Title of the app. |
description |
Description of the app. The content will be wrapped by a |
hline |
Whether to add the horizontal line (by |
html |
HTML fragment inserted below the heatmap. The value can be a string or be wrapped by |
heatmap_id |
Pass to |
title1 |
Pass to |
title2 |
Pass to |
width1 |
Pass to |
height1 |
Pass to |
width2 |
Pass to |
height2 |
Pass to |
width3 |
Pass to |
layout |
Pass to |
compact |
Pass to |
action |
Pass to |
cursor |
Pass to |
response |
Pass to |
brush_opt |
Pass to |
output_ui_float |
Pass to |
show_cell_fun |
Whether show graphics made by |
show_layer_fun |
Whether show graphics made by |
save |
The value can be set to a folder name so that the shiny app is saved into several files. |
app_options |
All pass to the |
With any Heatmap
/HeatmapList
object, directly send to htShiny()
to create a Shiny app for the heatmap(s):
htShiny(ht_list)
If the heatmaps are already drawn, ht_list
can be omitted and the last heatmap object is retrieved automatically:
Heatmap(...) + other_heatmaps_or_annotations # or other functions that internally use Heatmap() htShiny()
A Shiny app object.
There are also many examples that can be get with htShinyExample
.
# use last generated heatmap if(interactive() && dev.interactive()) { m = matrix(rnorm(100), 10) Heatmap(m) htShiny() } # by providing a heatmap/heatmap list if(interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) htShiny(ht) } # vertical heatmap list if(interactive()) { m1 = matrix(rnorm(100), 10) rownames(m1) = 1:10 colnames(m1) = 1:10 ht1 = Heatmap(m1, row_km = 2, column_km = 2) m2 = matrix(sample(letters[1:10], 100, replace = TRUE), 10) ht2 = Heatmap(m2) ht_list = draw(ht1 + ht2) htShiny(ht_list) ht_list = ht1 %v% ht2 htShiny(ht_list) } # compact mode if(interactive()) { m = matrix(rnorm(100), 10) Heatmap(m) htShiny(compact = TRUE) }
# use last generated heatmap if(interactive() && dev.interactive()) { m = matrix(rnorm(100), 10) Heatmap(m) htShiny() } # by providing a heatmap/heatmap list if(interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) htShiny(ht) } # vertical heatmap list if(interactive()) { m1 = matrix(rnorm(100), 10) rownames(m1) = 1:10 colnames(m1) = 1:10 ht1 = Heatmap(m1, row_km = 2, column_km = 2) m2 = matrix(sample(letters[1:10], 100, replace = TRUE), 10) ht2 = Heatmap(m2) ht_list = draw(ht1 + ht2) htShiny(ht_list) ht_list = ht1 %v% ht2 htShiny(ht_list) } # compact mode if(interactive()) { m = matrix(rnorm(100), 10) Heatmap(m) htShiny(compact = TRUE) }
Examples of interactive complex heatmaps
htShinyExample(which)
htShinyExample(which)
which |
An index of which example to use. The list of all examples can be obtained by executing |
In every example, there is a Shiny app opened, which also includes source code that generates this app.
A Shiny app object.
# list all examples htShinyExample() if(interactive()) { htShinyExample(4.2) }
# list all examples htShinyExample() if(interactive()) { htShinyExample(4.2) }
Generic function for interactivate an object in an interactive Shiny app
interactivate(x, ...)
interactivate(x, ...)
x |
An object. |
... |
Other arguments. |
# There is no example NULL
# There is no example NULL
Visualize DESeq2 result in an interactive Shiny app
## S3 method for class 'DESeqDataSet' interactivate(x, res = DESeq2::results(x), seed = 123, ...)
## S3 method for class 'DESeqDataSet' interactivate(x, res = DESeq2::results(x), seed = 123, ...)
x |
A |
res |
The object returned by |
seed |
Random seed. It is mainly set for the random colors of annotations. |
... |
Other arguments. |
if(interactive()) { require(airway) data(airway) se = airway require(DESeq2) dds = DESeqDataSet(se, design = ~ dex) keep = rowSums(counts(dds)) >= 10 dds = dds[keep, ] dds$dex = relevel(dds$dex, ref = "untrt") dds = DESeq(dds) interactivate(dds) }
if(interactive()) { require(airway) data(airway) se = airway require(DESeq2) dds = DESeqDataSet(se, design = ~ dex) keep = rowSums(counts(dds)) >= 10 dds = dds[keep, ] dds$dex = relevel(dds$dex, ref = "untrt") dds = DESeq(dds) interactivate(dds) }
Interactive Shiny application for 2D density distribution
## S3 method for class 'kde' interactivate(x, ...)
## S3 method for class 'kde' interactivate(x, ...)
x |
a |
... |
Other arguments. |
if(interactive()) { require(ks) lt = readRDS(system.file("extdata", "2d_density_xy.rds", package = "InteractiveComplexHeatmap")) data = cbind(lt$x, lt$y) fit = kde(data) interactivate(fit) }
if(interactive()) { require(ks) lt = readRDS(system.file("extdata", "2d_density_xy.rds", package = "InteractiveComplexHeatmap")) data = cbind(lt$x, lt$y) fit = kde(data) interactivate(fit) }
Interactive Shiny application for 2D density distribution
interactivateDensity2D(x, y, ...)
interactivateDensity2D(x, y, ...)
x |
A numeric vector. |
y |
A numeric vector. |
... |
All pass to |
if(interactive()) { lt = readRDS(system.file("extdata", "2d_density_xy.rds", package = "InteractiveComplexHeatmap")) interactivateDensity2D(lt$x, lt$y) }
if(interactive()) { lt = readRDS(system.file("extdata", "2d_density_xy.rds", package = "InteractiveComplexHeatmap")) interactivateDensity2D(lt$x, lt$y) }
Interactive complex heatmap modal dialog
InteractiveComplexHeatmapModal( input, output, session, ht_list, heatmap_id = NULL, # parameters passed to InteractiveComplexHeatmapOutput() title1 = "Original heatmap", title2 = "Selected sub-heatmap", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 370, height2 = 350, width3 = ifelse(layout == "(1-2)|3", 800, 370), layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui = TRUE, output_ui_float = FALSE, # parameters passed to makeInteractiveComplexHeatmap() click_action = NULL, brush_action = NULL, # other configurations js_code = "", close_button = TRUE, cancel_action = c("remove", "hide"))
InteractiveComplexHeatmapModal( input, output, session, ht_list, heatmap_id = NULL, # parameters passed to InteractiveComplexHeatmapOutput() title1 = "Original heatmap", title2 = "Selected sub-heatmap", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 370, height2 = 350, width3 = ifelse(layout == "(1-2)|3", 800, 370), layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui = TRUE, output_ui_float = FALSE, # parameters passed to makeInteractiveComplexHeatmap() click_action = NULL, brush_action = NULL, # other configurations js_code = "", close_button = TRUE, cancel_action = c("remove", "hide"))
input |
Passed from the Shiny server function. |
output |
Passed from the Shiny server function. |
session |
Passed from the Shiny server function. |
ht_list |
A |
heatmap_id |
ID of the plot. If it is not specified, an internal ID is assigned. |
title1 |
Pass to |
title2 |
Pass to |
width1 |
Pass to |
height1 |
Pass to |
width2 |
Pass to |
height2 |
Pass to |
width3 |
Pass to |
layout |
Pass to |
compact |
Pass to |
action |
Pass to |
cursor |
Pass to |
response |
Pass to |
brush_opt |
Pass to |
output_ui |
Pass to |
output_ui_float |
Pass to |
click_action |
Pass to |
brush_action |
Pass to |
js_code |
Additional JavaScript code that is put after the interactive heatmap UI. The value can be a text or a function that takes "heatmap ID" as the argument and returns the formatted JavaScript code. |
close_button |
Whether to add a close button at the end of the widget. If it is |
cancel_action |
Whether to remove the UI from HTML or just hide it when the UI is closed. |
It creates an interactive heatmap "modal dialog" according to a certain action.
The function is normally put inside observe
or observeEvent
.
No value is returned.
if(interactive()) { require(ComplexHeatmap) ui = fluidPage( actionButton("show_heatmap", "Generate_heatmap"), ) 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) }
if(interactive()) { require(ComplexHeatmap) ui = fluidPage( actionButton("show_heatmap", "Generate_heatmap"), ) 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) }
UI for the interactive complex heatmaps
InteractiveComplexHeatmapOutput(heatmap_id = NULL, title1 = "Original heatmap", title2 = "Selected sub-heatmap", title3 = if(output_ui_float) NULL else "Output", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 400, height2 = 350, width3 = NULL, layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui = default_output_ui(heatmap_id), output_ui_float = FALSE, containment = FALSE, internal = FALSE, ...)
InteractiveComplexHeatmapOutput(heatmap_id = NULL, title1 = "Original heatmap", title2 = "Selected sub-heatmap", title3 = if(output_ui_float) NULL else "Output", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 400, height2 = 350, width3 = NULL, layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui = default_output_ui(heatmap_id), output_ui_float = FALSE, containment = FALSE, internal = FALSE, ...)
heatmap_id |
ID of the plot. If it is not specified, an internal ID is assigned. |
title1 |
Title of the original heatmap. |
title2 |
Title of the sub-heatmap. |
title3 |
Title of the output. |
width1 |
Width of the original heatmap. |
height1 |
Height of the original heatmap. |
width2 |
Width of the sub-heatmap. |
height2 |
Height of the sub-heatmap. |
width3 |
Width of the output div. |
layout |
One of |
compact |
If the value is |
action |
Which action for selecting single cells on the heatmap? Value should be |
cursor |
When moving mouse on heatmap, whether to show the cursors on the four sides? |
response |
Which action needs to be responded on the server side? Value should be in |
brush_opt |
A list of parameters passed to |
output_ui |
A |
output_ui_float |
Whether the UI defined by |
containment |
Whether the resizing is restricted in a certain parent div? Value can be |
internal |
Internally used. |
... |
Pass to the UI container which is wrapped by |
This function generates HTML fragment for the interactive UI. See the example in makeInteractiveComplexHeatmap
page.
layout
is defined as follows (1
for the original heatmap, 2
for the selected sub-heatmap and 3
is for the output:
"(1-2)|3"
: Heatmap and sub-heatmap are in a same row, and output is in a second row. This is the default layout.
"1|(2-3)"
: Heatmap is in a single row, while sub-heatmap and output are in a second row.
"1-2-3"
: All three components are in a same row.
"1|2|3"
: Each component is in a single row.
"1-(2|3)"
: Being different from the other four layouts, this is a two-column layout. Heatmap is in a sigle column. Sub-heatmap and output are vertically aligned and the two are in the second column.
The hover event is implemented with https://github.com/websanova/mousestop .
A UI that can be used in Shiny.
# There is no example NULL
# There is no example NULL
Interactive complex heatmap widget
InteractiveComplexHeatmapWidget( input, output, session, ht_list, heatmap_id = NULL, output_id, # parameters passed to InteractiveComplexHeatmapOutput() title1 = "Original heatmap", title2 = "Selected sub-heatmap", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 370, height2 = 350, width3 = ifelse(layout == "(1-2)|3", 800, 370), layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui = TRUE, output_ui_float = FALSE, # parameters passed to makeInteractiveComplexHeatmap() click_action = NULL, brush_action = NULL, # other configurations js_code = "", close_button = TRUE, cancel_action = c("remove", "hide"))
InteractiveComplexHeatmapWidget( input, output, session, ht_list, heatmap_id = NULL, output_id, # parameters passed to InteractiveComplexHeatmapOutput() title1 = "Original heatmap", title2 = "Selected sub-heatmap", width1 = ifelse(layout == "1|(2-3)", 800, 450), height1 = ifelse(layout == "1-(2|3)", 700, 350), width2 = 370, height2 = 350, width3 = ifelse(layout == "(1-2)|3", 800, 370), layout = ifelse("brush" %in% response, "(1-2)|3", "1-3"), compact = FALSE, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), output_ui = TRUE, output_ui_float = FALSE, # parameters passed to makeInteractiveComplexHeatmap() click_action = NULL, brush_action = NULL, # other configurations js_code = "", close_button = TRUE, cancel_action = c("remove", "hide"))
input |
Passed from the Shiny server function. |
output |
Passed from the Shiny server function. |
session |
Passed from the Shiny server function. |
ht_list |
A |
heatmap_id |
ID of the plot. If it is not specified, an internal ID is assigned. |
output_id |
Where the heatmap is put. |
title1 |
Pass to |
title2 |
Pass to |
width1 |
Pass to |
height1 |
Pass to |
width2 |
Pass to |
height2 |
Pass to |
width3 |
Pass to |
layout |
Pass to |
compact |
Pass to |
action |
Pass to |
cursor |
Pass to |
response |
Pass to |
brush_opt |
Pass to |
output_ui |
Pass to |
output_ui_float |
Pass to |
click_action |
Pass to |
brush_action |
Pass to |
js_code |
Additional JavaScript code that is put after the interactive heatmap UI. The value can be a text or a function that takes "heatmap ID" as the argument and returns the formatted JavaScript code. |
close_button |
Whether to add a close button at the end of the widget. |
cancel_action |
Whether to remove the UI from HTML or just hide it when the UI is closed. |
It creates an interactive heatmap widget according to a certain action. The UI is placed to the output ID that user defined.
The function is normally put inside observe
or observeEvent
.
No value is returned.
if(interactive()) { require(ComplexHeatmap) ui = fluidPage( actionButton("show_heatmap", "Generate_heatmap"), htmlOutput("heatmap_output") ) server = function(input, output, session) { m = matrix(rnorm(100), 10) ht = Heatmap(m) observeEvent(input$show_heatmap, { InteractiveComplexHeatmapWidget(input, output, session, ht, output_id = "heatmap_output") }) } shiny::shinyApp(ui, server) }
if(interactive()) { require(ComplexHeatmap) ui = fluidPage( actionButton("show_heatmap", "Generate_heatmap"), htmlOutput("heatmap_output") ) server = function(input, output, session) { m = matrix(rnorm(100), 10) ht = Heatmap(m) observeEvent(input$show_heatmap, { InteractiveComplexHeatmapWidget(input, output, session, ht, output_id = "heatmap_output") }) } shiny::shinyApp(ui, server) }
Test whether it is in sub heatmap
is_in_sub_heatmap()
is_in_sub_heatmap()
Normally, it is used in cell_fun
/layer_fun
.
# There is no example NULL
# There is no example NULL
Process heatmaps on the sever side
makeInteractiveComplexHeatmap(input, output, session, ht_list, heatmap_id = shiny_env$current_heatmap_id, click_action = NULL, hover_action = NULL, dblclick_action = NULL, brush_action = NULL, res = 72, show_cell_fun = TRUE, show_layer_fun = TRUE)
makeInteractiveComplexHeatmap(input, output, session, ht_list, heatmap_id = shiny_env$current_heatmap_id, click_action = NULL, hover_action = NULL, dblclick_action = NULL, brush_action = NULL, res = 72, show_cell_fun = TRUE, show_layer_fun = TRUE)
input |
Passed from the Shiny server function. |
output |
Passed from the Shiny server function. |
session |
Passed from the Shiny server function. |
ht_list |
A |
heatmap_id |
The corresponding heatmap ID from the UI. If there is only one interactive heatmap in the app, this argument does not need to be specified and it will use the current one used in |
click_action |
Additional actions on the server side when receiving a click event on the UI. This self-defined function should accept two or four arguments. If it is two arguments, they should be |
hover_action |
Additional actions at the server side when receiving a hover event on the UI. |
dblclick_action |
Additional actions at the server side when receiving a dblclick event on the UI. |
brush_action |
Additional actions at the server side when receiving a brush event on the UI. |
res |
Resolution of the plot, pass to |
show_cell_fun |
Whether show graphics made by |
show_layer_fun |
Whether show graphics made by |
No value is returned.
if(interactive()) { ht = Heatmap(m) ht = draw(ht) ui = fluidPage( InteractiveComplexHeatmapOutput() ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht) } shiny::shinyApp(ui, server) }
if(interactive()) { ht = Heatmap(m) ht = draw(ht) ui = fluidPage( InteractiveComplexHeatmapOutput() ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht) } shiny::shinyApp(ui, server) }
UI for the original heatmap
originalHeatmapOutput(heatmap_id, title = NULL, width = 450, height = 350, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), containment = FALSE, internal = FALSE)
originalHeatmapOutput(heatmap_id, title = NULL, width = 450, height = 350, action = "click", cursor = TRUE, response = c(action, "brush"), brush_opt = list(stroke = "#f00", opacity = 0.6), containment = FALSE, internal = FALSE)
heatmap_id |
ID of the plot. |
title |
Title of the original heatmap. |
width |
Width of the original heatmap. |
height |
Height of the original heatmap. |
action |
Which action for selecting single cells on the heatmap? Value should be |
cursor |
When moving mouse on heatmap, whether to show the cursors on the four sides? |
response |
Which action needs to be responded on the server side? Value should be in |
brush_opt |
A list of parameters passed to |
containment |
Whether the resizing is restricted in a certain parent div? Value can be |
internal |
Internally used. |
subHeatmapOutput
, HeatmapInfoOutput
.
if(interactive()) { require(shinydashboard) m = matrix(rnorm(100), 10) ht = Heatmap(m) body = dashboardBody( fluidRow( box(title = "Original heatmap", width = 4, solidHeader = TRUE, status = "primary", originalHeatmapOutput("ht") ), box(title = "Sub-heatmap", width = 4, solidHeader = TRUE, status = "primary", subHeatmapOutput("ht") ), box(title = "Output", width = 4, solidHeader = TRUE, status = "primary", HeatmapInfoOutput("ht") ) ) ) ui = dashboardPage( dashboardHeader(), dashboardSidebar(), body ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht, "ht") } shinyApp(ui, server) }
if(interactive()) { require(shinydashboard) m = matrix(rnorm(100), 10) ht = Heatmap(m) body = dashboardBody( fluidRow( box(title = "Original heatmap", width = 4, solidHeader = TRUE, status = "primary", originalHeatmapOutput("ht") ), box(title = "Sub-heatmap", width = 4, solidHeader = TRUE, status = "primary", subHeatmapOutput("ht") ), box(title = "Output", width = 4, solidHeader = TRUE, status = "primary", HeatmapInfoOutput("ht") ) ) ) ui = dashboardPage( dashboardHeader(), dashboardSidebar(), body ) server = function(input, output, session) { makeInteractiveComplexHeatmap(input, output, session, ht, "ht") } shinyApp(ui, server) }
A random matrix
data(rand_mat)
data(rand_mat)
Following code was used to generate rand_mat
:
set.seed(123) rand_mat = cbind(rbind(matrix(rnorm(20*20, mean = 1, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20)), rbind(matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 1, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0, sd = 0.5), nr = 20)), rbind(matrix(rnorm(20*20, mean = 0.5, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 0.5, sd = 0.5), nr = 20), matrix(rnorm(20*20, mean = 1, sd = 0.5), nr = 20)) ) + matrix(rnorm(60*60, sd = 0.5), nr = 60) colnames(rand_mat) = paste0("C", 1:60) rownames(rand_mat) = paste0("R", 1:60)
Zuguang Gu <[email protected]>
data(rand_mat) rand_mat
data(rand_mat) rand_mat
Record the observation object
record_observation(obs, heatmap_id = shiny_env$current_heatmap_id)
record_observation(obs, heatmap_id = shiny_env$current_heatmap_id)
obs |
Observation object returned by |
heatmap_id |
The Heatmap ID. |
# There is no example NULL
# There is no example NULL
Select an area in the heatmap
selectArea(ht_list = get_last_ht(), pos1 = NULL, pos2 = NULL, mark = TRUE, verbose = TRUE, ht_pos = NULL, include_annotation = FALSE, calibrate = TRUE)
selectArea(ht_list = get_last_ht(), pos1 = NULL, pos2 = NULL, mark = TRUE, verbose = TRUE, ht_pos = NULL, include_annotation = FALSE, calibrate = TRUE)
ht_list |
A |
mark |
Whether to mark the selected area as a rectangle. |
pos1 |
If the value is |
pos2 |
Another point as |
verbose |
Whether to print messages. |
ht_pos |
A value returned by |
include_annotation |
Internally used. |
calibrate |
Internally used. Mainly works for Rstudio desktop IDE. |
The regions can be selected interactively or selected manually by setting pos1
and pos2
.
A DataFrame
object with row indices and column indices corresponding to the selected region.
if(dev.interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) selectArea(ht) set.seed(123) ht = Heatmap(m, row_km = 2, column_km = 2) ht = draw(ht) selectArea(ht) }
if(dev.interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) selectArea(ht) set.seed(123) ht = Heatmap(m, row_km = 2, column_km = 2) ht = draw(ht) selectArea(ht) }
Select a position in the heatmap
selectPosition(ht_list = get_last_ht(), pos = NULL, mark = TRUE, verbose = TRUE, ht_pos = NULL, calibrate = TRUE)
selectPosition(ht_list = get_last_ht(), pos = NULL, mark = TRUE, verbose = TRUE, ht_pos = NULL, calibrate = TRUE)
ht_list |
A |
mark |
Whether to mark the selected position as a point. |
pos |
If the value is |
verbose |
Whether to print messages. |
ht_pos |
A value returned by |
calibrate |
Internally used. Mainly works for Rstudio desktop IDE. |
The regions can be selected interactively or selected manually by setting pos
.
A DataFrame
object with row indices and column indices corresponding to the selected position.
if(dev.interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) selectPosition(ht) }
if(dev.interactive()) { m = matrix(rnorm(100), 10) rownames(m) = 1:10 colnames(m) = 1:10 ht = Heatmap(m) ht = draw(ht) selectPosition(ht) }
UI for the sub-heatmaps
subHeatmapOutput(heatmap_id, title = NULL, width = 400, height = 350, containment = FALSE, internal = FALSE)
subHeatmapOutput(heatmap_id, title = NULL, width = 400, height = 350, containment = FALSE, internal = FALSE)
heatmap_id |
ID of the plot. |
title |
Title of the sub-heatmap. |
width |
Width of the sub-heatmap. |
height |
Height of the sub-heatmap. |
containment |
Whether the resizing is restricted in a certain parent div? Value can be |
internal |
Internally used. |
# See examples on the help page of originalHeatmapOutput()
# See examples on the help page of originalHeatmapOutput()