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,
  ...
)

Arguments

plot

A ggplot 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)

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

...

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.