| Title: | Interactive Web Widgets for Vellum Scenes |
|---|---|
| Description: | Turns a 'vellum' scene (or a 'vellumplot' plot) into a self-contained, client-side interactive HTML widget: hover tooltips and highlighting, click selection, rectangular brush-select, pan/zoom, and a toolbar -- driven by the per-element data keys, bounding boxes, and 'scene_model()' metadata that 'vellum' emits. Requires no Shiny and no server round-trip. |
| Authors: | David Schoch [aut, cre] |
| Maintainer: | David Schoch <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0.9000 |
| Built: | 2026-07-12 18:40:00 UTC |
| Source: | https://github.com/r-vellum/vellumwidget |
as_widget() is the terminal verb of the interactivity pipeline: it compiles
its input to a vellum scene, emits the SVG (with per-element data-keys) and
the vellum::scene_model() element table, and bundles them with the vellumwidget
JavaScript runtime into a self-contained htmlwidgets::createWidget() widget.
The result does hover tooltips, hover highlighting, and click selection
entirely client-side — no Shiny, no server round-trip. Pan/zoom, brush, and
selection work with mouse, touch (drag to pan, two-finger pinch to zoom), and
keyboard input: the arrows pan and +/-/0 zoom and reset, except that with
accessibility on (the default) the arrows move between marks while one is
focused — see the a11y argument.
as_widget( x, width = NULL, height = NULL, tooltip = TRUE, hover = TRUE, select = TRUE, brush = TRUE, zoom = TRUE, toolbar = TRUE, nearest = TRUE, a11y = TRUE, alt = NULL, hover_color = NULL, selected_color = NULL, dim_opacity = NULL, tooltip_style = NULL, export_filename = NULL, export_scale = NULL, group = NULL, crosstalk = NULL, select_mode = c("multiple", "single"), elementId = NULL )as_widget( x, width = NULL, height = NULL, tooltip = TRUE, hover = TRUE, select = TRUE, brush = TRUE, zoom = TRUE, toolbar = TRUE, nearest = TRUE, a11y = TRUE, alt = NULL, hover_color = NULL, selected_color = NULL, dim_opacity = NULL, tooltip_style = NULL, export_filename = NULL, export_scale = NULL, group = NULL, crosstalk = NULL, select_mode = c("multiple", "single"), elementId = NULL )
x |
A |
width, height
|
Widget size (any valid CSS size, or |
tooltip, hover, select
|
Toggles for the three hover/click interactions
(all |
brush, zoom, toolbar
|
Toggles for rectangular brush-select, wheel/drag
pan-zoom (via the SVG |
nearest |
When |
a11y |
Accessibility (default |
alt |
Accessible label (alt text) for the chart as a whole. Defaults to
the scene's own title/description — which |
hover_color, selected_color
|
Outline colours for hovered / selected
elements (any R or CSS colour), applied widget-wide. |
dim_opacity |
Opacity (0–1) of the non-hovered elements while hovering
(default |
tooltip_style |
Optional named list styling the tooltip box:
|
export_filename, export_scale
|
The download filename base (no extension;
default |
group |
Optional linking group name. Widgets sharing a |
crosstalk |
Optional crosstalk::SharedData (or a crosstalk group name
string) to link this widget with the crosstalk ecosystem (plotly, leaflet,
DT, and crosstalk's |
select_mode |
|
elementId |
Optional explicit widget DOM id. |
Interactivity is driven by the keys/metadata a plot declares. In vellumplot these
come from the reserved data_id / tooltip / hover_group mark arguments; a
plot that declares none renders as a static (but still embeddable) SVG. A
hovered element with a data_id but no tooltip shows its key.
The scene metadata vellumwidget reads — the vellum::scene_model() element
table and the SVG data-key / data-vellum-* attributes — is specified in
vellum's "The scene contract" vignette
(vignette("scene-contract", package = "vellum")).
An htmlwidget of class "vellumwidget".
## Not run: library(vellumplot) df <- data.frame(wt = mtcars$wt, mpg = mtcars$mpg, model = rownames(mtcars)) vplot(df) |> mark_point(x = wt, y = mpg, tooltip = model, data_id = model) |> as_widget() ## End(Not run)## Not run: library(vellumplot) df <- data.frame(wt = mtcars$wt, mpg = mtcars$mpg, model = rownames(mtcars)) vplot(df) |> mark_point(x = wt, y = mpg, tooltip = model, data_id = model) |> as_widget() ## End(Not run)
Standard htmlwidgets output/render helpers so a vellumwidget widget can appear in
a Shiny app or an interactive R Markdown document.
vellumwidgetOutput(outputId, width = "100%", height = "400px") renderVellumwidget(expr, env = parent.frame(), quoted = FALSE)vellumwidgetOutput(outputId, width = "100%", height = "400px") renderVellumwidget(expr, env = parent.frame(), quoted = FALSE)
outputId |
Shiny output slot id. |
width, height
|
Widget size. |
expr |
An expression producing a |
env, quoted
|
Standard non-standard-evaluation plumbing. |
vellumwidgetOutput(): a Shiny output UI element. renderVellumwidget(): a Shiny
render function.
A widget rendered as vellumwidgetOutput("plot") reports the user's interactions back
to the server as reactive inputs, keyed by the output id. All values are the
element data keys (the data_id a vellumplot mark declares); map them back to
your data by that key.
input$plot_selectedCharacter vector of the currently selected keys
(click / brush / keyboard, and any selection arriving from a linked widget).
Updates as state — re-selecting the same set is a no-op. character(0) when
nothing is selected.
input$plot_clickA list list(key=) for each click; key is NULL
for a click on empty space. An event input — fires on every click, even the
same mark twice.
input$plot_hoverThe hovered key, or NULL when the pointer leaves a
mark. Updates as state (re-fires only when the hovered key changes).
input$plot_brushA list list(keys=, x0=, y0=, x1=, y1=) when a
brush gesture completes: the selected keys and the brushed rectangle in the
scene's device-pixel (viewBox) coordinates. An event input.
These are emitted only inside a live Shiny session; a static render (knitr,
pkgdown, htmltools::save_html()) produces identical output and no input
traffic. Driving the widget from the server (setting selection without a
re-render) is a planned addition.