inst/shiny-demo/signal-set-get/readme.md

This example shows how we can design a chart using Vega-Lite, then use Shiny to set a signal and retrieve its value from the chart. This example shows a histogram with a Shiny input to control the bin-width; we communicate the bin-width to the chart using a signal.

The difference between using a signal and re-creating the chart in the server() function is that by using the signal, the chart is recalculated by Vega, in the client browser. Instead of communicating an entire chart-specification (including data) upon each change, Shiny has to communicate only a single number, the bin-width.

Signals are not a part of the Vega-Lite definition, so we have to "hack" a signal into our Vega-Lite chart, then patch the compiled Vega specification using the patch option in vega_embed(). This follows an Observable example written by Vega-Lite developer Dominik Moritz. As of the start of 2019, the integration of signals in to the Vega-Lite definition is an ongoing discussion.

In the server function, we use a couple of functions to set the signal value in the chart, and to get the signal value from the chart:



Try the vegawidget package in your browser

Any scripts or data that you put into this service are public.

vegawidget documentation built on Sept. 3, 2023, 9:07 a.m.