to_spec: Convert a spec created with widget idioms to JSON

Description Usage Arguments Value Examples

View source: R/fromspec.r

Description

Takes an htmlwidget object and turns it into a JSON Vega-Lite spec

Usage

1
to_spec(vl, pretty = TRUE, to_cb = FALSE)

Arguments

vl

a Vega-Lite object

pretty

if TRUE (default) then a "pretty-printed" version of the spec will be returned. Use FALSE for a more compact version.

to_cb

if TRUE, will copy the spec to the system clipboard. Default is FALSE.

Value

JSON spec

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
dat <- jsonlite::fromJSON('[
    {"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43},
    {"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53},
    {"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52}
  ]')

vegalite() %>%
  add_data(dat) %>%
  encode_x("a", "ordinal") %>%
  encode_y("b", "quantitative") %>%
  mark_bar() -> chart

to_spec(chart)

vegalite documentation built on May 2, 2019, 10:46 a.m.