Skip to contents

Internal function that creates an interactive MAIDR widget from a ggplot object. This is called internally by render_maidr() and should not be called directly. Use maidr_output() and render_maidr() for Shiny integration instead.

Usage

maidr_widget(
  plot,
  use_cdn = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL,
  fig_width = NULL,
  fig_height = NULL,
  hover_mode = NULL,
  ...
)

Arguments

plot

A ggplot object, a lattice (trellis) object, or NULL to auto-detect recorded Base R plots

use_cdn

Logical. Controls where MAIDR.js is loaded from, matching show() and save_html():

  • TRUE: Use CDN (requires internet), loading the latest published MAIDR.js unless maidr.cdn_version pins one

  • FALSE: Use local bundled files (works offline)

  • NULL (default): Auto-detect based on internet availability

This differs from maidr_html_dependencies(), where NULL means bundled. The widget renders through create_maidr_iframe() and create_standalone_html(), which probes for connectivity, so an unset use_cdn loads from the CDN on a machine that is online.

width

The width of the widget in pixels or CSS units (default: NULL for auto-sizing)

height

The height of the widget in pixels or CSS units (default: NULL for auto-sizing)

element_id

A unique identifier for the widget (default: NULL for auto-generated)

fig_width, fig_height

The size to draw the chart at, in inches, as width and height set it in show(): each a single positive number no larger than 50, or NULL (the default) for 7 x 5 in, 12 x 6 in for a candlestick chart. Not the widget's size, which width and height set; a chart wider than the widget shrinks to fit it.

hover_mode

The chart's starting hover mode, as in show(): "pointermove", "click" or "off", or NULL (the default) for getOption("maidr.hover_mode").

...

Additional arguments passed to create_maidr_html()

Value

An htmlwidget object that can be displayed in RStudio, Shiny, or saved as HTML

Details

Uses iframe-based isolation to ensure MAIDR.js initializes properly. Each widget gets its own isolated JavaScript context where MAIDR.js can discover and initialize the SVG with maidr-data attribute.