Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Created May 8, 2017 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/655c4b529a89d4f4d0aba2f69583f64f to your computer and use it in GitHub Desktop.
Save cpsievert/655c4b529a89d4f4d0aba2f69583f64f to your computer and use it in GitHub Desktop.
Use restyle to add some points after initial render
library(plotly)
library(htmlwidgets)
plot_ly(x = c(1, 2), y = c(1, 2)) %>%
onRender(
'function(el, x) {
setTimeout(function() {
var gd = document.getElementById(el.id);
var obj = {"mode": "markers"};
for (var i = 0; i < 10; i++) {
var j = i + 2;
var x = "x[" + j + "]";
var y = "y[" + j + "]";
// iteration values
obj[x] = [j];
// likelihood
obj[y] = [Math.random()];
Plotly.restyle(gd, obj);
}
}, 1000)
}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment