There are three types of information you can get from a Vega chart, a signal, data (i.e. a dataset), and information associated with an event. A dataset or a signal must first be defined and named in the vegaspec.
vw_shiny_get_signal(outputId, name, body_value = "value")vw_shiny_get_data(outputId, name, body_value = "value")
vw_shiny_get_event(outputId, event, body_value = "datum")
character
, shiny outputId
for the vegawidget
character
, name of the signal (defined in Vega specification)
being monitored
character
or JS_EVAL
, the body of a JavaScript
function that Vega will use to handle the signal or event; this function
must return a value
character
, type of the event being monitored, e.g. "click"
,
for list of supported events, please see
Vega Event-Stream reference
shiny::reactive()
function that returns the value returned by
body_value
These getter-functions are called from within
a Shiny server()
function, where they act like
shiny::reactive()
, returning a reactive expression.
To see these functions in action, you can run a shiny-demo:
vw_shiny_get_signal()
: call vw_shiny_demo("signal-set-get")
vw_shiny_get_data()
: call vw_shiny_demo("data-set-get")
vw_shiny_get_event()
: call vw_shiny_demo("event-get")
In addition to the chart outputId
, you will need to provide:
vw_shiny_get_signal()
: the name
of the signal, as defined in the Vega
specification
vw_shiny_get_data()
: the name
of the dataset, as defined in the Vega
specification
vw_shiny_get_event()
: the event
type, as defined in the
Vega Event-Stream reference
When the signal or data changes, or when the event fires, Vega needs to know which information you want returned to Shiny. To do this, you provide a JavaScript handler-function:
vw_shiny_get_signal()
: the default handler,
vw_handler_signal("value")
,
specifies that the value of the signal be returned.
vw_shiny_get_data()
: the default handler,
vw_handler_data("value")
,
specifies that the entire dataset be returned.
vw_shiny_get_event()
: the default handler,
vw_handler_event("datum")
,
specifies that the single row of data associated with graphical mark
be returned. For example, if you are monitoring a "click"
event,
Vega would return the row of data that backs any mark
(like a point) that you click.
If you need to specify a different behavior for the handler, there are a
couple of options. This package provides
a library of handler-functions; call vw_handler_signal()
,
vw_handler_data()
, or vw_handler_event()
without arguments to
list the available handlers.
If the library does not contain the handler you need, the body_value
argument will also accept a character string which will be used as
the body of the handler function.
For example, these calls are equivalent:
vw_shiny_get_signal(..., body_value = "value")
vw_shiny_get_signal(..., body_value = vw_handler_signal("value"))
vw_shiny_get_signal(..., body_value = "return value;")
If you use a custom-handler that you think may be useful for the handler-function library, please file an issue.
vw_handler_signal()
, vw_handler_event()
,
vega-view:
addSignalListener(),
addEventListener()