rbokeh Version 0.4.1 Released

The rbokeh package version 0.4.1 was recently released.

The most major addition in 0.4 is support for javascript callbacks for custom interactivity, which I’ll provide an example of below and will be posting about in more detail soon. Thanks to initial work on this from Jonathan Owen and recent help and motivation from Saptarshi Guha.

In addition to JS callbacks, additional improvements were made to non-standard evaluation from Barret Schloerke. Many other minor improvements were made, which are listed below in detail.

A CRAN release is imminent, but for now you can install the latest version with the following:

install.packages("rbokeh", repos = c(CRAN = "http://cran.rstudio.com",
  tessera = "http://packages.tessera.io"))

Callback support

Javascript callbacks allow you to specify custom behavior to be triggered when a user performs certain interactions with your rbokeh plots. Currently callbacks can be triggered by range change events (through panning / zooming), selection events (by clicking or box/lasso-select), and hover events.

Callback support has been a feature of Bokeh for a while but we’ve been working on the best way to expose it in the R interface. This should be considered an experimental feature for rbokeh, in that we may slightly change the interface after getting more use cases in order, but we are exposing it so that people can start playing with it.

Here is an example. I’ll go into detail about how these work and how can make your own in future posts.

dat <- data.frame(x = runif(500), y = runif(500))

p <- figure(title = "select points to adjust mean line",
  tools = "lasso_select") %>%
  ly_points(x, y, data = dat, lname = "points") %>%
  ly_lines(x = c(0, 1), y = rep(mean(dat$y), 2), line_width = 6,
    color = "orange", alpha = 0.75, lname = "mean")

code <- "
  var inds = cb_obj.get('selected')['1d'].indices;
  var d = cb_obj.get('data');
  var ym = 0;

  if (inds.length == 0) { return; }

  for (i = 0; i < inds.length; i++) {
    ym += d['y'][inds[i]];
  }
  ym /= inds.length;

  mean_data.get('data').y = [ym, ym];

  cb_obj.trigger('change');
  mean_data.trigger('change');
"

p %>% tool_lasso_select(custom_callback(code, "mean"), "points")

Another noteworthy addition is callbacks that allow plot interaction events to trigger Shiny application events, so that you can get more interactivity out of rbokeh plots in your Shiny apps without writing a line of javascript. More on this soon!

For the impatient, you can find several examples here, here, here, here, and here.

List of updates

  • add width argument to ly_boxplot (0.4.1)
  • update BokehJS to 0.11.1 (0.4.1)
  • unname vectors to make jsonlite happy (0.4.1)
  • fix bug in hover glyph for lines with mapped attrs (0.4.1)
  • many fixes and streamlining of non-standard evaluation logic (0.4.1)
  • add args argument to some callbacks (0.4.1)
  • update hexbin to have xbnds, ybnds and allow hover = FALSE (0.4.1)
  • add visible to list of valid opts for checking (0.4.0)
  • fix issue with hiding legend when mapping attributes (0.4.0)
  • propagate visible parameter to all glyphs (0.4.0)
  • add hover glyph to have same properties as specified glyph with full opacity (0.4.0)
  • fix issue with custom legend (0.4.0)
  • add visible parameter to all glyphs (0.4.0)
  • modularize get_glyph_attrs() so can be used for annotations (0.4.0)
  • add selection callbacks (0.4.0)
  • add annotation renderers to tools (0.4.0)
  • change default tooltip colors (0.4.0)
  • fix js callbacks to have unique ids (0.4.0)
  • add hover callback example - thanks @saptarshiguha (0.4.0)
  • refactor callback approach (0.4.0)
  • add get_object_refs() method (0.4.0)
  • fix bug in axis range introduced by range callback (0.4.0)
  • fix layer naming defaults (0.4.0)
  • add tool_tap with callback support (0.4.0)
  • update layer_ref to callback tools (0.4.0)
  • fix lname to be singleton (0.4.0)
  • add callback examples (0.4.0)
  • make callback work with specified layer names (0.4.0)
  • add hover and tap callbacks (0.4.0)
  • add range callback support (0.4.0)
  • set default log level to ‘info’ with debug available through option (0.4.0)
Avatar
Ryan Hafen
Data Scientist, Statistical Consultant

Related