There are two ways to change a Vega chart: by setting
a signal or by setting a dataset; you can also
direct a Vega chart to re-run itself. Any signal or
dataset you set must first be defined and named in the vegaspec.
These functions are called from within
a Shiny server() function, where they act like
shiny::observe() or shiny::observeEvent().
vw_shiny_set_signal(outputId, name, value, run = TRUE, ...)
vw_shiny_set_data(outputId, name, value, run = TRUE, ...)
vw_shiny_run(outputId, value, ...)character, shiny outputId for the vegawidget
character, name of the signal or dataset being set,
as defined in the vegaspec
reactive expression, e.g. input$slider or dataset(),
that returns the value to which to set the signal or dataset
logical indicates if the chart is to be run immediately
other arguments passed on to shiny::observeEvent()
shiny::observeEvent() function that responds to changes in the
reactive-expression value
To see these functions in action, you can run a shiny-demo:
vw_shiny_set_signal(): call vw_shiny_demo("signal-set-get")
vw_shiny_set_data(): call vw_shiny_demo("data-set-get")
vw_shiny_run(): call vw_shiny_demo("data-set-swap-run")
For the signal and data setters, in addition to the chart outputId,
you will need to provide:
the name of the signal or dataset you wish to keep updated
the value to which you want to set the signal or dataset;
this should be a reactive expression like input$slider or rct_dataset()
whether or not you want to run the Vega view again immediately
after setting this value
If you do not set run = TRUE in the setter-function,
you can use the vw_shiny_run() function to control when
the chart re-runs. One possibility is to set its value to a reactive
expression that refers to, for example, a shiny::actionButton().