Visualize data using a custom D3 visualization script

r2d3(
  data,
  script,
  css = "auto",
  dependencies = NULL,
  options = NULL,
  d3_version = c("6", "5", "4", "3"),
  container = "svg",
  elementId = NULL,
  width = NULL,
  height = NULL,
  sizing = default_sizing(),
  viewer = c("internal", "external", "browser")
)

Arguments

data

Data to be passed to D3 script.

script

JavaScript file containing the D3 script.

css

CSS file containing styles. The default value "auto" will use any CSS file located alongside the script file with the same stem (e.g. "barplot.css" would be used for "barplot.js") as well as any CSS file with the name "styles.css".

dependencies

Additional HTML dependencies. These can take the form of paths to JavaScript or CSS files, or alternatively can be fully specified dependencies created with htmltools::htmlDependency.

options

Options to be passed to D3 script.

d3_version

Major D3 version to use, the latest minor version is automatically picked.

container

The 'HTML' container of the D3 output.

elementId

Use an explicit element ID for the widget (rather than an automatically generated one). Useful if you have other JavaScript that needs to explicitly discover and interact with a specific widget instance.

width

Desired width for output widget.

height

Desired height for output widget.

sizing

Widget sizing policy (see htmlwidgets::sizingPolicy).

viewer

"internal" to use the RStudio internal viewer pane for output; "external" to display in an external RStudio window; "browser" to display in an external browser.

Details

In order to scope CSS styles when multiple widgets are rendered, the Shadow DOM and the wecomponents polyfill is used, this feature can be turned off by setting the r2d3.shadow option to FALSE.

Examples


library(r2d3)
r2d3(
  data = c (0.3, 0.6, 0.8, 0.95, 0.40, 0.20),
  script = system.file("examples/barchart.js", package = "r2d3")
)