R/alt.R

Defines functions as_chart

Documented in as_chart

# see zzz.R for "creation" of the alt object

#' Create Altair chart from vegaspec
#'
#' @inheritParams as_vegaspec
#'
#' @return altair object
#'
#' @examples
#'   if (interactive()) {
#'     as_chart(vegawidget::spec_mtcars)
#'   }
#' @export
#'
as_chart <- function(spec) {

  spec <- as_vegaspec(spec)
  spec <- vegawidget::vw_as_json(spec)

  chart <- alt$Chart()$from_json(spec)

  chart
}

Try the altair package in your browser

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

altair documentation built on Sept. 4, 2023, 9:06 a.m.