| Title: | Interactive WebGL Scatterplots for Biological Data Exploration |
|---|---|
| Description: | Lightweight 'htmlwidgets' interface to the JavaScript 'regl-scatterplot' library, rendering millions of two-dimensional points in the browser via WebGL. Designed for exploratory visualisation of single-cell, spatial transcriptomics and other high-dimensional biological data. Features include synchronised pan/zoom across multiple plots, categorical and continuous colour mapping, lasso selection, range and category filtering, PNG/SVG/PDF export, and Shiny integration. The widget works in the 'RStudio' Viewer, standalone HTML files, Shiny applications and Jupyter notebooks running the 'IRkernel'. |
| Authors: | George Muñoz [aut, cre] (ORCID: <https://orcid.org/0009-0007-3765-9967>) |
| Maintainer: | George Muñoz <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.3 |
| Built: | 2026-06-19 13:36:08 UTC |
| Source: | https://github.com/BiocStaging/reglScatterplotR |
Enables (or disables) synchronised pan/zoom across the reglScatterplot
widgets identified by plotIds. Must be called from inside a Shiny
reactive context.
enableReglScatterplotSync( plotIds, enabled = TRUE, session = shiny::getDefaultReactiveDomain() )enableReglScatterplotSync( plotIds, enabled = TRUE, session = shiny::getDefaultReactiveDomain() )
plotIds |
Character vector of |
enabled |
Logical; |
session |
Shiny session object (defaults to the active one). |
Invisibly NULL. Called for its side effect of sending a custom
message to the browser.
if (interactive()) { enableReglScatterplotSync(c("plotA", "plotB")) }if (interactive()) { enableReglScatterplotSync(c("plotA", "plotB")) }
A small, synthetic single-cell-style dataset for trying out
reglScatterplot() without downloading anything or installing a
Bioconductor data package. It mimics a PBMC UMAP: eight cell-type clusters
arranged as Gaussian blobs in two dimensions, plus a handful of continuous
covariates and one marker-gene-like gradient.
data(reglScatterExample)data(reglScatterExample)
A data.frame with 3,400 rows (cells) and 7 columns:
Numeric. Two-dimensional UMAP coordinates.
Factor with 8 levels ("CD4 T", "CD8 T", "NK",
"B", "Monocyte", "Dendritic", "Platelet", "Progenitor").
Use as a categorical colorBy.
Integer. Total counts per cell (library size).
Integer. Number of detected features per cell.
Numeric. Percent mitochondrial counts (0-25).
Numeric. Log-normalised expression of a T/NK marker, with
dropout. Use as a continuous colorBy.
The data are simulated (see data-raw/make_reglScatterExample.R)
and carry no biological meaning beyond being shaped like real scRNA-seq
output. They exist purely so the examples, vignette and tests have
something realistic to draw.
Simulated. Generation script in data-raw/.
data(reglScatterExample) # Colour by cell type (categorical) reglScatterplot(reglScatterExample, x = "UMAP_1", y = "UMAP_2", colorBy = "celltype" ) # Colour by a continuous marker gene reglScatterplot(reglScatterExample, x = "UMAP_1", y = "UMAP_2", colorBy = "CD3D", continuousPalette = "viridis", vmax = "p99" )data(reglScatterExample) # Colour by cell type (categorical) reglScatterplot(reglScatterExample, x = "UMAP_1", y = "UMAP_2", colorBy = "celltype" ) # Colour by a continuous marker gene reglScatterplot(reglScatterExample, x = "UMAP_1", y = "UMAP_2", colorBy = "CD3D", continuousPalette = "viridis", vmax = "p99" )
Renders a regl-scatterplot widget capable of displaying millions of
points in the browser. Works in standalone HTML, the RStudio Viewer,
Shiny applications and Jupyter notebooks (via IRkernel).
reglScatterplot( data = NULL, x, y, colorBy = NULL, groupBy = NULL, assay = NULL, filterBy = NULL, pointSize = NULL, opacity = NULL, pointColor = NULL, sizeBy = NULL, opacityBy = NULL, tooltipBy = NULL, pixelRatio = NULL, categoricalPalette = "Set1", continuousPalette = "viridis", customPalette = NULL, customColors = NULL, pointLabels = NULL, xlab = "X", ylab = "Y", title = NULL, legendTitle = NULL, xrange = NULL, yrange = NULL, rangePadding = 0.15, vmin = NULL, vmax = NULL, centerZero = FALSE, showAxes = TRUE, showTooltip = TRUE, backgroundColor = NULL, axisColor = "#333333", legendBg = "#ffffff", legendText = "#000000", legendOpacity = NULL, legendBlur = NULL, toolbarPosition = "none", zoomOnSelection = FALSE, legendPosition = "top-right", draggableLegend = TRUE, width = NULL, height = NULL, enableDownload = FALSE, plotId = NULL, syncPlots = NULL, elementId = NULL, dataVersion = NULL, masterId = NULL, autoFit = FALSE, margins = NULL, fontSize = 12, legendFontSize = 12, filteredIndices = NULL, selectedIndices = NULL, syncState = TRUE )reglScatterplot( data = NULL, x, y, colorBy = NULL, groupBy = NULL, assay = NULL, filterBy = NULL, pointSize = NULL, opacity = NULL, pointColor = NULL, sizeBy = NULL, opacityBy = NULL, tooltipBy = NULL, pixelRatio = NULL, categoricalPalette = "Set1", continuousPalette = "viridis", customPalette = NULL, customColors = NULL, pointLabels = NULL, xlab = "X", ylab = "Y", title = NULL, legendTitle = NULL, xrange = NULL, yrange = NULL, rangePadding = 0.15, vmin = NULL, vmax = NULL, centerZero = FALSE, showAxes = TRUE, showTooltip = TRUE, backgroundColor = NULL, axisColor = "#333333", legendBg = "#ffffff", legendText = "#000000", legendOpacity = NULL, legendBlur = NULL, toolbarPosition = "none", zoomOnSelection = FALSE, legendPosition = "top-right", draggableLegend = TRUE, width = NULL, height = NULL, enableDownload = FALSE, plotId = NULL, syncPlots = NULL, elementId = NULL, dataVersion = NULL, masterId = NULL, autoFit = FALSE, margins = NULL, fontSize = 12, legendFontSize = 12, filteredIndices = NULL, selectedIndices = NULL, syncState = TRUE )
data |
Optional input object. Accepts a |
x, y
|
Either column names (when |
colorBy |
Optional column name or vector used to colour points. Character/factor input is treated as categorical, numeric as continuous. |
groupBy |
Optional column name or vector. Used by the legend to expose
a second categorical filter that intersects with |
assay |
Name of the assay to read when |
filterBy |
Optional |
pointSize, opacity
|
Numeric. When |
pointColor |
Optional fixed hex colour. When given, overrides
|
sizeBy, opacityBy
|
Optional numeric column name or vector mapped to point size / opacity. They share one data channel, so both encode the same variable. |
tooltipBy |
Optional extra fields to show on hover: column name(s) (when
|
pixelRatio |
Optional numeric device-pixel-ratio for the WebGL backing
store. When |
categoricalPalette, continuousPalette
|
Names of fallback palettes
(a |
customPalette, customColors
|
Optional explicit palettes. |
pointLabels |
Optional character vector aligned to the points; shown in the hover tooltip. Use this for gene names, cell barcodes, etc. |
xlab, ylab, title, legendTitle
|
Axis/labels. |
xrange, yrange
|
Optional length-2 numeric vectors fixing the axes
instead of using the data range. When supplied, they bypass the
automatic padding from |
rangePadding |
Fractional padding added to each side of the data
range when |
vmin, vmax
|
Continuous-colour clipping. Accepts a number, |
centerZero |
Logical. If |
showAxes, showTooltip
|
Logical toggles. |
backgroundColor, axisColor, legendBg, legendText
|
Hex colour overrides for cosmetic styling. |
legendOpacity |
Opacity (0-1) of the frosted legend card background.
|
legendBlur |
Backdrop blur in pixels behind the legend card. |
toolbarPosition |
Show an in-plot toolbar (pan / lasso / zoom-to-
selection / reset / screenshot). One of |
zoomOnSelection |
Logical; when |
legendPosition |
Starting position of the legend. One of
|
draggableLegend |
Logical; when |
width, height
|
Widget dimensions (any valid CSS unit). When |
enableDownload |
Logical. Show the download (PNG/SVG/PDF) button.
Defaults to |
plotId |
Optional string identifying the plot. Required when linking
plots together via |
syncPlots |
Optional character vector of plot ids to sync with. |
elementId |
DOM id for the containing div (passed to |
dataVersion |
Optional integer/string used by the JS layer to detect when the underlying data has changed. |
masterId |
Optional id of another plot whose camera should seed this one's view (used when a plot is added to an already-synced group). |
autoFit |
Logical. When |
margins |
Optional |
fontSize, legendFontSize
|
Numeric font sizes in pixels. |
filteredIndices, selectedIndices
|
Optional 0-based integer vectors for server-driven filtering / selection. |
syncState |
Logical. When |
An htmlwidgets object of class "reglScatterplot".
When data is a SingleCellExperiment or SpatialExperiment, the
function reroutes through a helper that pulls coordinates from
reducedDim() (e.g. x = "UMAP") - or from spatialCoords() when
x = "spatial" for a SpatialExperiment. colorBy and groupBy
may then name either a colData column or a feature in rownames(sce)
(in the latter case assay() is read - "logcounts" by default, or the
assay named by the assay argument).
When data is a Seurat object, coordinates come from Embeddings() for
the reduction named by x (default "UMAP", matched case-insensitively;
falls back to the first of umap/tsne/pca present). colorBy and
groupBy are resolved with FetchData(), so they may name either a
meta.data column or a feature. For Seurat, the assay argument selects
the layer to read for features ("data", i.e. log-normalised, by
default; works with both v4 slots and v5 layers); to colour by a
non-default modality such as ADT, set Seurat::DefaultAssay() before
calling.
When data is an in-memory AnnData (from anndataR or the anndata
CRAN package), coordinates come from an obsm embedding named by x
(default "UMAP", auto-prefixed to the scanpy-style "X_umap" and matched
case-insensitively). colorBy / groupBy resolve against obs columns or
var_names features, and assay selects the layer to read for features
(NULL -> X, a layer name, or "raw"). An AnnData read with
zellkonverter::readH5AD() arrives as a SingleCellExperiment and uses the
SCE path above instead.
enableReglScatterplotSync(), updateReglPointSize()
set.seed(1L) df <- data.frame( x = rnorm(2000), y = rnorm(2000), group = sample(letters[1:4], 2000, replace = TRUE), score = runif(2000) ) reglScatterplot(df, x = "x", y = "y", colorBy = "group") reglScatterplot(df, x = "x", y = "y", colorBy = "score", continuousPalette = "magma" ) # Single-cell UMAP from a SingleCellExperiment # reglScatterplot(sce, dimred = "UMAP", colorBy = "cluster") # Colour by a gene # reglScatterplot(sce, dimred = "UMAP", colorBy = "MS4A1") # Spatial coordinates from a SpatialExperiment # reglScatterplot(spe, dimred = "spatial", colorBy = "celltype")set.seed(1L) df <- data.frame( x = rnorm(2000), y = rnorm(2000), group = sample(letters[1:4], 2000, replace = TRUE), score = runif(2000) ) reglScatterplot(df, x = "x", y = "y", colorBy = "group") reglScatterplot(df, x = "x", y = "y", colorBy = "score", continuousPalette = "magma" ) # Single-cell UMAP from a SingleCellExperiment # reglScatterplot(sce, dimred = "UMAP", colorBy = "cluster") # Colour by a gene # reglScatterplot(sce, dimred = "UMAP", colorBy = "MS4A1") # Spatial coordinates from a SpatialExperiment # reglScatterplot(spe, dimred = "spatial", colorBy = "celltype")
Output and render functions for using reglScatterplot() inside Shiny
applications and interactive R Markdown documents.
reglScatterplotOutput(outputId, width = "100%", height = "600px") renderReglScatterplot(expr, env = parent.frame(), quoted = FALSE)reglScatterplotOutput(outputId, width = "100%", height = "600px") renderReglScatterplot(expr, env = parent.frame(), quoted = FALSE)
outputId |
Output variable name (character). |
width, height
|
CSS unit (e.g. |
expr |
An expression that produces a |
env |
Environment in which to evaluate |
quoted |
Is |
reglScatterplotOutput() returns a Shiny output element;
renderReglScatterplot() returns a render function.
if (interactive()) { ui <- shiny::fluidPage(reglScatterplotOutput("plot")) server <- function(input, output, session) { output$plot <- renderReglScatterplot({ reglScatterplot(iris, x = "Sepal.Length", y = "Sepal.Width", colorBy = "Species" ) }) } shiny::shinyApp(ui, server) }if (interactive()) { ui <- shiny::fluidPage(reglScatterplotOutput("plot")) server <- function(input, output, session) { output$plot <- renderReglScatterplot({ reglScatterplot(iris, x = "Sepal.Length", y = "Sepal.Width", colorBy = "Species" ) }) } shiny::shinyApp(ui, server) }
Serialises a numeric vector as little-endian 32-bit floats and prefixes the
result with "base64:" so the companion JavaScript widget recognises it as
a binary buffer rather than a JSON array. Using this transfer path keeps
the payload size at ~25% of the equivalent JSON representation.
toBase64(vec)toBase64(vec)
vec |
Numeric vector. |
Character string of the form "base64:..." or NULL.
toBase64(c(1, 2, 3.5))toBase64(c(1, 2, 3.5))
Update the point size of one or more scatterplots
updateReglPointSize(plotIds, size, session = shiny::getDefaultReactiveDomain())updateReglPointSize(plotIds, size, session = shiny::getDefaultReactiveDomain())
plotIds |
Character vector of plot ids whose size should be updated. |
size |
Numeric pixel size. |
session |
Shiny session. |
Invisibly NULL.
if (interactive()) { updateReglPointSize("plotA", size = 5) }if (interactive()) { updateReglPointSize("plotA", size = 5) }