Input UI components for the ComplexHeatmap module
Source:R/ComplexHeatmap_Heatmap_module_ui.R
ComplexHeatmap_HeatmapInputsUI.RdThis should be placed in the UI where the inputs should be shown, with an id
that matches the id used in the ComplexHeatmap_HeatmapServer() and
ComplexHeatmap_HeatmapOutputUI() functions.
Arguments
- id
The ID for the Shiny module.
- data
The data frame used for plot generation, or a list with a
matrixdata frame (required) and acolumn_annotationsdata frame (optional) — seeComplexHeatmap_HeatmapServer()'sdataparameter for details. Row-annotation choices come frommatrix's columns; column-annotation choices (and the "Column Annotations" tab controls) only appear whencolumn_annotationsis supplied.- defaults
A named list of default values for the inputs. An entry may also be a
shiny::reactive()orshiny::reactiveVal(); it is resolved withshiny::isolate()to seed the control, and the module then keeps it live (seesetup_reactive_defaults()).- title
An optional title for the UI grid.
- columns
Number of columns for the UI grid.
Details
Unlike the other plotly-based modules, this module wraps
ComplexHeatmap::Heatmap() and renders its interactive output via the
InteractiveComplexHeatmap package. The incoming data frame is converted
to a numeric matrix (see the Data / Matrix tab) before being passed to
Heatmap().
The inputs are organized into a grid via organize_inputs(), with columns
controlling the number of columns in the grid. Defaults for each input can be
supplied via the defaults argument (see get_default()).
Plot parameters and defaults
The following ComplexHeatmap::Heatmap() parameters can be accessed via UI
inputs and/or the defaults argument:
matrix.cols- Numeric columns forming the matrix (UI: "Matrix Columns", default: all numeric columns)rowname.col- Column used as row names (UI: "Row Name Column", default: "")name- Heatmap / legend title (UI: "Heatmap Name", default: "value")na_col- Color forNAcells (UI: "NA Color", default: "grey")scale- Z-score the matrix by row, column, or not at all (UI: "Scale", default: "None"). Applied before plotting only — row/column annotation values and the source-data download always use the unscaled matrix. Scaling happens after the Filter tab's row/column filters, so a Z-score describes only the rows and columns on screen.reverse.palette- Reverse the palette (UI: "Reverse Palette", default: FALSE)low_color,mid_color,high_color- Colors for the low/mid/high end of the value scale, i.e. whatcolinComplexHeatmap::Heatmap()is built from viacirclize::colorRamp2()(UI: "Low/Mid/High Color", default: blue/white/red)min_value,mid_value,max_value- Values mapped tolow_color/mid_color/high_color(UI: "Min/Mid/Max Value", default: NA = derived from the matrix: min,mean(range(mat)), and max respectively)show_heatmap_legend- Show the heatmap legend (UI: "Show Legend", default: TRUE)border- Draw heatmap border (UI: "Border", default: FALSE)cluster_rows- Cluster rows (UI: "Cluster Rows", default: TRUE)cluster_columns- Cluster columns (UI: "Cluster Columns", default: TRUE)clustering_distance_rows- Row distance metric (UI: "Row Distance", default: "euclidean")clustering_distance_columns- Column distance metric (UI: "Column Distance", default: "euclidean")clustering_method_rows- Row linkage method (UI: "Row Method", default: "complete")clustering_method_columns- Column linkage method (UI: "Column Method", default: "complete")show_row_dend- Show row dendrogram (UI: "Show Row Dendrogram", default: TRUE)show_column_dend- Show column dendrogram (UI: "Show Column Dendrogram", default: TRUE)row_split_by- Row split method: "None", "K-means", "Hierarchical", or "Annotation" (UI: "Row Split Method", default: "None"). Only one split mechanism is ever active per axis, which avoids the errorComplexHeatmap::Heatmap()raises when both a k-means and a hierarchical split are requested at once.row_split_n- Number of row groups, used whenrow_split_byis "K-means" or "Hierarchical" (UI: "Row Groups", default: NA; clamped to the number of matrix rows)row_split_cols- Columns whose values group the rows, used whenrow_split_byis "Annotation" (UI: "Row Split Columns", default: none). Several columns give nested slices, one per observed combination. Values come from the same place row annotation tracks read, so a split and a track on one column always agree.column_split_by- Column split method: "None", "K-means", "Hierarchical", or "Annotation" (UI: "Column Split Method", default: "None")column_split_n- Number of column groups, used whencolumn_split_byis "K-means" or "Hierarchical" (UI: "Column Groups", default: NA; clamped to the number of matrix columns)column_split_cols- Columns of thecolumn_annotationstable whose values group the heatmap columns, used whencolumn_split_byis "Annotation" (UI: "Column Split Columns"; only shown whendatasupplies acolumn_annotationstable; default: none)row_gap- Gap between row slices, mm (UI: "Row Gap (mm)", default: 1)column_gap- Gap between column slices, mm (UI: "Column Gap (mm)", default: 1)row_title- Row title (UI: "Row Title", default: "")column_title- Column title (UI: "Column Title", default: ""). A title, when set, replaces the group names a split would otherwise title its slices with; a%sin it is filled in with each slice's group name. The same goes forrow_title.show_row_slice_titles- Title each row slice with its group name when the rows are split androw_titleis blank (UI: "Show Row Slice Titles", default: TRUE). Applies to every split method: annotation values for "Annotation", cluster numbers for "K-means" and "Hierarchical". Untick it to remove the titles and the space they take.show_column_slice_titles- The same for columns (UI: "Show Column Slice Titles", default: TRUE)show_row_names- Show row names (UI: "Show Row Names", default: TRUE)show_column_names- Show column names (UI: "Show Column Names", default: TRUE)row_names_side- Row names side (UI: "Row Names Side", default: "right")column_names_side- Column names side (UI: "Column Names Side", default: "bottom")column_names_rot- Column name rotation (UI: "Column Name Rotation", default: 90)row_names_fontsize- Row name font size (UI: "Row Name Size", default: 12)column_names_fontsize- Column name font size (UI: "Column Name Size", default: 12)title_fontsize- Row/column title font size (UI: "Title Size", default: 13.2)row_annotations- Row annotation tracks, built asComplexHeatmap::rowAnnotation()and passed asleft_annotation/right_annotationper row (UI: "Annotations" tab, "Row Annotations"multiDynamicInput()— each row picks amatrixcolumn, a side (Left or Right), and the side and font size of that track's own name label (Bottom or Top, since ComplexHeatmap places a row annotation's name above or below it), and whether that track contributes a legend ("Show Legend", defaultTRUE); default: none). Each row's color control appears just below the list once a column is picked: numeric columns get Low/Mid/High color pickers, everything else gets amultiColorPicker()with one color per level. Seed those colors fromdefaultswith a named color vector keyed by the annotation's column name — the row names in arow_annotations/column_annotationsdefault are not stable, since the client reports rows back asrow1,row2, ...column_key- Column incolumn_annotationsmatched against the matrix's selected column names (UI: "Annotations" tab, "Column Key"; only shown whendatasupplies acolumn_annotationstable)column_annotations- Column annotation tracks, built asComplexHeatmap::columnAnnotation()and passed astop_annotation/bottom_annotationper row (UI: "Annotations" tab, "Column Annotations"multiDynamicInput()— each row picks a column, a side (Top or Bottom), the side and font size of that track's own name label (Right or Left, since ComplexHeatmap places a column annotation's name beside it), and whether that track contributes a legend ("Show Legend", defaultTRUE), with the same per-row color controls as row annotations; only shown whendatasupplies acolumn_annotationstable; default: none)
Plot parameters implementing new functionality
The "Filter" tab's two inputs have no ComplexHeatmap::Heatmap() equivalent — they
narrow the matrix before it is built, so a specific set of genes or samples can be
plotted without wiring up the separate dataFilter module:
row_filter- Expression keeping only the matching rows (UI: "Row Filter", default: ""). Evaluated against thematrixdata frame, so every one of its columns is in scope — annotation columns, the row-name column, and the matrix columns themselves.column_filter- Expression keeping only the matching matrix columns (UI: "Column Filter", default: ""). Matrix columns are sample names rather than rows of a data frame, so the expression is evaluated against a frame built with one row per selected matrix column: a syntheticcolumnfield holding the column name, plus every field ofcolumn_annotationsjoined viacolumn_key.column %in% c("Healthy_1", "Healthy_2")therefore works with no metadata table at all, whilecondition == "Disease"works as soon as one is supplied. Ifcolumn_annotationsalready has a field namedcolumn, the real one wins and no synthetic is added.
Both are evaluated with safe_eval_filter(), which permits comparisons, &/|/!,
%in%, is.na(), arithmetic, and the string helpers grepl, startsWith, endsWith,
substr, nchar, toupper, tolower, and trimws. Anything else — a function call
outside that list, or a symbol that is not a column — is rejected and reported in the UI
rather than evaluated. An expression yielding NA for a row drops that row.
Filtering runs before everything else: scale, the annotation tracks, the split methods,
and the source download all describe the filtered matrix.
Both inputs are debounced by 700ms, so the heatmap redraws once you pause rather than on every keystroke of a half-typed expression.
Plot parameters not implemented
The following ComplexHeatmap::Heatmap() parameters are not exposed because
they require R code, objects, or annotations that do not map cleanly to UI
inputs: cell_fun, layer_fun, post_fun, rect_gp, border_gp,
custom col mapping functions for the annotation tracks (beyond the Low/Mid/High colors and
multiColorPicker), row_order / column_order, row_labels / column_labels,
jitter, and all rasterization parameters (use_raster, raster_*).
Examples
if (FALSE) { # interactive()
library(VizModules)
ComplexHeatmap_HeatmapInputsUI("heatmap", example_heatmap_matrix)
}