Fit a hand-built InteractiveComplexHeatmap widget to its container's width
Source:R/ComplexHeatmap_Heatmap_module_ui.R
heatmap_fit_width.RdThe heatmap module's output functions already do this (see their fit.width
argument). This is the same behaviour for an app that calls
InteractiveComplexHeatmap::InteractiveComplexHeatmapOutput() itself rather
than going through the module — a heatmap driven directly by
InteractiveComplexHeatmap::makeInteractiveComplexHeatmap(), say.
Usage
heatmap_fit_width(
ui,
heatmap_id,
panels = c("heatmap", "sub_heatmap"),
output = TRUE
)Arguments
- ui
The UI returned by
InteractiveComplexHeatmap::InteractiveComplexHeatmapOutput()(or theoriginalHeatmapOutput()/subHeatmapOutput()pair).- heatmap_id
The
heatmap_idpassed to that output function.- panels
Character vector of panels to scale. Defaults to both; pass just
"heatmap"for acompact = TRUEwidget, which has no sub-heatmap.- output
Logical; also scale the click/brush info panel. Defaults to
TRUE, matching whatComplexHeatmap_HeatmapOutputUI()does for the same combined widget; passFALSEwhen the app lays that panel out itself.
Details
InteractiveComplexHeatmapOutput() bakes its width1/width2 into the page
as fixed pixels, so the widget over- or under-fills whatever room the app
actually gives it until the resize handle is dragged. Wrapping the output in
this rescales the panels to their container once the page is laid out; the
widget's own resize controls still win afterwards.
A widget on a tab that is not the active one has no width to measure on load. It is fitted when its container is first laid out instead, so a heatmap the user has not opened yet is still correct the moment they do.
See also
ComplexHeatmap_HeatmapOutputUI(), whose fit.width argument is
the module-side equivalent.
Examples
if (interactive() && requireNamespace("InteractiveComplexHeatmap", quietly = TRUE)) {
heatmap_fit_width(
InteractiveComplexHeatmap::InteractiveComplexHeatmapOutput(
heatmap_id = "my_ht", width1 = 1480, height1 = 500
),
heatmap_id = "my_ht"
)
}