shiny-getters {vegawidget} | R Documentation |
Get information from a Vega chart into Shiny
Description
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.
Usage
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")
Arguments
outputId |
|
name |
|
body_value |
|
event |
|
Details
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()
: callvw_shiny_demo("signal-set-get")
-
vw_shiny_get_data()
: callvw_shiny_demo("data-set-get")
-
vw_shiny_get_event()
: callvw_shiny_demo("event-get")
In addition to the chart outputId
, you will need to provide:
-
vw_shiny_get_signal()
: thename
of the signal, as defined in the Vega specification -
vw_shiny_get_data()
: thename
of the dataset, as defined in the Vega specification -
vw_shiny_get_event()
: theevent
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.
Value
shiny::reactive()
function that returns the value returned by
body_value
See Also
vw_handler_signal()
, vw_handler_event()
,
vega-view:
addSignalListener(),
addEventListener()