add-listeners: Add JavaScript listeners

add-listenersR Documentation

Add JavaScript listeners

Description

Listeners are how we get information out of a Vega chart and into the JavaScript environment. To do this, we specify handler-functions to run whenever a certain signal changes or an event fires.

Usage

vw_add_signal_listener(x, name, handler_body)

vw_add_data_listener(x, name, handler_body)

vw_add_event_listener(x, event, handler_body)

Arguments

x

vegawidget object to be monitored

name

character, name of the signal or dataset to be monitored

handler_body

character or JS_EVAL, text of the body of the JavaScript handler-function to be called when the signal or dataset changes, or the event fires

event

character, name of the type of event to be monitored, e.g. "click"

Details

The handler_body can be the text of the body of a JavaScript function; the arguments to this function will vary according to the type of listener you are adding:

  • signal-handler and data-handler arguments: name, value

  • event-handler arguments: event, item

This package offers some functions to make it easier to build JavaScript handler functions from R: vw_handler_signal(), vw_handler_data(), and vw_handler_event(). You can pipe one of these functions to vw_handler_add_effect() to perform side-effects on the result.

Value

modified copy of vegawidget object x

See Also

vw_handler_signal(), vw_handler_data(), vw_handler_event(), vw_handler_add_effect(), vega-view


vegawidget documentation built on May 29, 2024, 12:17 p.m.