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

character, shiny outputId for the vegawidget

name

character, name of the signal (defined in Vega specification) being monitored

body_value

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

event

character, type of the event being monitored, e.g. "click", for list of supported events, please see Vega Event-Stream reference

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:

In addition to the chart outputId, you will need to provide:

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:

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:

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()


[Package vegawidget version 0.5.0 Index]