vegawidget v0.3.2


Monthly downloads



'Htmlwidget' for 'Vega' and 'Vega-Lite'

'Vega' and 'Vega-Lite' parse text in 'JSON' notation to render chart-specifications into 'HTML'. This package is used to facilitate the rendering. It also provides a means to interact with signals, events, and datasets in a 'Vega' chart using 'JavaScript' or 'Shiny'.


status lifecycle R-CMD-check


Vega-Lite is an implementation of the grammar-of-graphics, rendered in the browser with interactivity.

The goal of vegawidget is to render Vega-Lite and Vega specifications as htmlwidgets, and to provide you a means to communicate with a Vega chart using JavaScript or Shiny. Its ambition is to be a low-level interface to the Vega(-Lite) API, such that other packages can build upon it to offer higher-level functions to compose Vega(-Lite) specifications.

Accordingly, this package may be useful to:

  • build (using lists of lists) re-usable Vega and Vega-Lite specifications for deployment elsewhere.
  • develop higher-level, user-friendly packages to build specific types of plots, or even to build a general ggplot2-like framework, using this package as the rendering foundation.


New to vegawidget 0.3.2

  • vegawidget offers Vega-Lite 4.17.0 and Vega 5.17.0. Consequently, this package works only with browsers that support ES6. This includes all modern browsers and the RStudioIDE (version 1.2 and later).

  • new function vw_set_base_url(), to set the option for vega-embed’s default baseURL.

  • changes vega_embed() to use ... to pass most of its arguments, making a more-forgiving connection to vega-embed.


You can install vegawidget from CRAN with:


The development version of vegawidget is available from GitHub with:

# install.packages("devtools")

Note: There are documentation websites for both the CRAN version and the development version of this package.


Vega(-Lite) specifications are just text, formatted as JSON. However, in R, we can use lists to build specifications:


spec_mtcars <-
    `$schema` = vega_schema(), # specifies Vega-Lite
    description = "An mtcars example.",
    data = list(values = mtcars),
    mark = "point",
    encoding = list(
      x = list(field = "wt", type = "quantitative"),
      y = list(field = "mpg", type = "quantitative"),
      color = list(field = "cyl", type = "nominal")
  ) %>% 

The as_vegaspec() function is used to turn the list into a vegaspec; many of this package’s functions are built to support, and render, vegaspecs:


The rendering of the chart above depends on where you are reading it:

  • On this package’s pkgdown site, it is rendered as part of an HTML environment, showing its full capabilities.

  • At its GitHub code site, the chart is further rendered to a static SVG file, then incorporated into the Markdown rendering.

For more, please see our Getting Started article. Additionally, the Vega-Lite website has a comprehensive introduction.

Other articles for this package:


  • Alicia Schep has been instrumental in guiding the evolution of the API, and for introducing new features, particularly the JavaScript and Shiny functions.
  • Haley Jeppson and Stuart Lee have provided valuable feedback and contributions throughout the package’s development.
  • Bob Rudis and the vegalite package provided a lot of the inspiration for this work, providing a high-level interface to Vega-Lite.
  • The Altair developers, for further popularizing the notion of using a programming language (Python) to create and render Vega-Lite specifications.
  • The Vega-Lite developers, for providing a foundation upon which the rest of this is built.


Contributions are welcome, please see this guide. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Functions in vegawidget

Name Description
shiny-getters Get information from a Vega chart into Shiny
%>% Pipe operator
knit_print.vegaspec Knit-print method
vw_handler Construct a vegawidget handler
vega_embed Vega embed options
vega_schema Create string for schema-URL
vw_handler_add_effect Add a side-effect to a JavaScript handler
vw_handler_body_compose Compose a JavaScript handler
vw_handler_signal Construct a JavaScript handler
shiny-setters Set information in a Vega chart from Shiny
spec_mtcars Example vegaspec: mtcars scatterplot
data_category Example dataset: Categorical data
vegawidgetOutput Shiny-output for vegawidget
renderVegawidget Render shiny-output for vegawidget
s3_register Register an s3 method
vegawidget Create a Vega/Vega-Lite htmlwidget
vega_version Determine Vega JavaScript versions
use_vegawidget Add vegawidget functions to your package
vw_as_json Coerce vegaspec to JSON
vw_serialize_data Serialize data-frame time-columns
vw_rename_datasets Rename datasets in a vegaspec
vw_spec_version Determine vegaspec version
vw_to_vega Convert to Vega specification
vw_autosize Autosize vegaspec
vw_shiny_demo Run Shiny demonstration-apps
vw_examine Examine vegaspec
vw_set_base_url Set base URL
.vw_handler_def Constructor for internal S3 class
as_vegaspec Coerce to vegaspec
glue_js Interpolate into a JavaScript string
add-listeners Add JavaScript listeners
.vw_handler_body Constructor for internal S3 class
image Create or write image
data_seattle_hourly Example dataset: Seattle hourly temperatures
data_seattle_daily Example dataset: Seattle daily weather
JS Mark character strings as literal JavaScript code
No Results!

Vignettes of vegawidget

No Results!

Last month downloads


SystemRequirements To use image and spec-compilation functions, i.e. suggests: nodejs (> 8), and for MacOS: X11
License MIT + file LICENSE
Encoding UTF-8
LazyData true
ByteCompile true
RoxygenNote 7.1.1
VignetteBuilder knitr
Language en-US
Config/testthat/edition 3
NeedsCompilation no
Packaged 2021-01-11 21:36:54 UTC; sesa19001
Repository CRAN
Date/Publication 2021-01-12 08:40:08 UTC

Include our badge in your README