Specifying: vegaspec

The central object of this package is a vegaspec, which is also a list. Use these functions to coerce to a vegaspec, format as JSON, or otherwise operate on a vegaspec. If you have V8 installed, you can compile a Vega-Lite specification to a Vega specification.

as_vegaspec()

Coerce to vegaspec

vw_examine()

Examine vegaspec

vw_as_json()

Coerce vegaspec to JSON

vw_autosize()

Autosize vegaspec

vw_rename_datasets()

Rename datasets in a vegaspec

vw_to_vega()

Convert to Vega specification

vw_spec_version()

Determine vegaspec version

vega_schema()

Create string for schema-URL

Rendering: vegawidget

The central side-effect of this package is to render a vegawidget, which is also an htmlwidget. A vegawidget is built using a vegaspec. A helper function is provided for vega-embed options. These options can be specified as an argument to the vegawidget function, or as an R option, vega.embed, which would picked up by the knit_print method. To knit to non-HTML-format, please consult the article on rendering

vegawidget()

Create a Vega/Vega-Lite htmlwidget

vega_embed()

Vega embed options

vw_set_base_url()

Set base URL

knit_print.vegaspec()

Knit-print method

Shiny

This package lets you render vegawidgets in Shiny. Once renrdered, it also provides functions to access Vega datasets, signals, and events from Shiny. The function vw_shiny_demo() lets you run any of this package’s demo apps; call it without arguments to see the list of available apps. This article on Shiny goes into some detail.

renderVegawidget()

Render shiny-output for vegawidget

vegawidgetOutput()

Shiny-output for vegawidget

vw_shiny_set_signal() vw_shiny_set_data() vw_shiny_run()

Set information in a Vega chart from Shiny

vw_shiny_get_signal() vw_shiny_get_data() vw_shiny_get_event()

Get information from a Vega chart into Shiny

vw_shiny_demo()

Run Shiny demonstration-apps

JavaScript

In addition to Shiny, this package provides functions to add JavaScript listeners to Vega charts and to compose JavaScript handlers. This lets you create interactivity in RMarkdown documents, but you are responsible for providing all the additional HTML and JS code to make it work. To see some examples, please see this article on JavaScript.

vw_add_signal_listener() vw_add_data_listener() vw_add_event_listener()

Add JavaScript listeners

vw_handler_signal() vw_handler_data() vw_handler_event()

Construct a JavaScript handler

vw_handler_add_effect()

Add a side-effect to a JavaScript handler

glue_js()

Interpolate into a JavaScript string

Data

This package provides some sample specifications and datasets.

spec_mtcars

Example vegaspec: mtcars scatterplot

data_category

Example dataset: Categorical data

data_seattle_daily

Example dataset: Seattle daily weather

data_seattle_hourly

Example dataset: Seattle hourly temperatures

Images

If you have V8 installed, you can convert and write a vegaspec or a vegawidget to SVG. To convert to a bitmap, or to write to a PNG file, you will need the rsvg and png packages.

vw_to_svg() vw_to_bitmap() vw_write_svg() vw_write_png()

Create or write image

Utilities

You can use use_vegawidget() to bring this package’s functionality to yours. Much like usethis::use_pipe() allows you to re-export the pipe in your package’s namespace, use_vegawidget() does this for many of these functions, as detailed in this article. The other functions deal with serializing date-times, and versions of Vega’s JavaScript libraries.

use_vegawidget() use_vegawidget_interactive()

Add vegawidget functions to your package

vw_serialize_data()

Serialize data-frame time-columns

vega_version() vega_version_all() vega_version_available()

Get Vega JavaScript versions