hd_add_js: Inject JavaScript into a Highcharts Widget

View source: R/theme.R

hd_add_jsR Documentation

Inject JavaScript into a Highcharts Widget

Description

Appends custom JavaScript to a highchart object via ⁠chart.events.<where>⁠. Use this for hand-written callbacks and plugins. For Highcharts built-in modules (accessibility, exporting, etc.) use highcharter::hc_add_dependency() instead.

Usage

hd_add_js(
  hc,
  code = NULL,
  file = NULL,
  plugin = NULL,
  where = c("load", "render")
)

Arguments

hc

A highchart object.

code

Character or NULL. Raw JavaScript string.

file

Character or NULL. Path to a .js file to read and inject.

plugin

Character or NULL. Name of a plugin bundled in ⁠inst/js/⁠.

where

"load" (default) or "render".

Details

Exactly one of code, file, or plugin must be supplied.

Value

The highchart object with JS injected.

Examples

if (interactive()) {
spec <- hd_spec(mtcars, "wt", "mpg")
fig  <- hd_make(spec, "scatter")
fig  <- hd_add_js(fig, code = "console.log('chart loaded');")
}


highdir documentation built on July 31, 2026, 5:06 p.m.