Interactive widget

Interactive
Any vellumplot becomes a client-side interactive widget with as_widget(): hover, select, brush, and zoom.

Pipe any vellumplot into as_widget() and it becomes a self-contained HTML widget: hover a point for a tooltip, click to select, drag a rectangle to brush, scroll to zoom. Nothing is re-drawn to get there. The widget ships the very SVG vellum solved, plus the table of where each element landed, so the interactive figure and the static one cannot drift apart. Picking measures to the mark itself rather than to the box around it.

Declare tooltip and data_id on the mark to give each point a label and a stable key for interactions.

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()

Map colour to a discrete variable and you get an interactive legend: hover a swatch to highlight its series, click to select it.

df$cyl <- factor(mtcars$cyl)

vplot(df) |>
  mark_point(x = wt, y = mpg, color = cyl, tooltip = model, data_id = model) |>
  as_widget()
Back to top