Much like IPython, the R kernel allows you to publish custom data types. When the frontend (here, nteract) recieves these, if it knows how to render these it will!
We'll use vegalite for a nice declarative way to compose vegalite graphs using the %>% operator and IRkernel's IRdisplay library for the displaying.
In [1]:
library(IRdisplay)
#'
#' Display a vegalite chart in supported jupyter frontends (nteract, jupyterlab)
#'
#' @param vl Vega-Lite object
#'
to_irkernel <- function(vl){
IRdisplay::publish_mimebundle(list('application/vnd.vegalite.v1+json'=vl$x))
}
In [2]:
library(vegalite)
vegalite() %>%
cell_size(400, 400) %>%
add_data("https://vega.github.io/vega-editor/app/data/cars.json") %>%
encode_x("Horsepower") %>%
encode_y("Miles_per_Gallon") %>%
encode_color("Origin", "nominal") %>%
mark_point() %>%
to_irkernel
In [ ]: