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")
shiny::reactive() function that returns the value returned by
These getter-functions are called from within
server() function, where they act like
shiny::reactive(), returning a reactive expression.
To see these functions in action, you can run a shiny-demo:
In addition to the chart
outputId, you will need to provide:
name of the signal, as defined in the Vega
name of the dataset, as defined in the Vega
event type, as defined in the
Vega Event-Stream reference
vw_shiny_get_signal(): the default handler,
specifies that the value of the signal be returned.
vw_shiny_get_data(): the default handler,
specifies that the entire dataset be returned.
vw_shiny_get_event(): the default handler,
specifies that the single row of data associated with graphical mark
be returned. For example, if you are monitoring a
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_event() without arguments to
list the available handlers.
If the library does not contain the handler you need, the
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.