question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New call signature for Plotly.plot

See original GitHub issue

Problem: Frames cannot be passed to the initial call to Plotly.plot. I don’t think breaking changes are required to change that fact, so this might be nice before it’s integrated in a bunch of different places. You also have to unpack plotly JSON data that almost certainly has the format:

{
  "data": [],
  "layout": {},
  "config": {},
  "frames": []
}

(Note: config is not fully serializable)

Currently to create a plot, you must run

Plotly.plot(gd, d.data, d.layout, d.config).then(function() {
  return Plotly.addFrames(gd, d.frames);
});

Possible solutions

It’s not bad, but the extra step seems unnecessary. Alternate proposed forms that could be implemented without breaking changes by overloading Plotly.plot:

Plotly.plot(gd, d.data, d.layout, d.config, d.frames);

Frames could simply be appended, though config seems nice as a final argument. Switching the last two arguments:

Plotly.plot(gd, d.data, d.layout, d.frames, d.config);

This case could be distinguished from the current form by the presence of an Array-typed fourth argument.

Taking a different approach and passing a single object:

Plotly.plot({
  container: gd,
  data: [],
  layout: {},
  config: {},
  frames: []
});

Except neither gd nor config are serializable, in general. Extracting the gd part, we get:

Plotly.plot(gd, {
  data: [],
  layout: {},
  config: {},
  frames: []
});

I rather like this final form since with some non-serializable exceptions in config (specifics?), you could simply pass fetched data toPlotly.plot in one go, i.e.:

fetch('path/to/my/data.json').then(function(d) {
  Plotly.plot(gd, d);
});

Which is nice and short, but then at the end of all of this, the conclusion is that this all exists only to save a bit of typing. I think it’s still worth discussing though since it seems sub-ideal that you can’t fully pass data (missing: frames) to a plot in a single command.

cc: @etpinard @chriddyp

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
etpinardcommented, Oct 24, 2016
1reaction
rreussercommented, Oct 12, 2016

@monfera yeah, was at least thinking it would auto-append a div to document.body and then only operate on the div.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Function reference in JavaScript - Plotly
Draws a new plot in an <div> element, overwriting any existing plot. ... The call signature and arguments for relayout are similar (but...
Read more >
Flexible Callback Signatures | Dash for Python Documentation
Flexible Callback Signatures in Dash 2.0 let you use keyword arguments, group arguments using dicts or tuples, and mix `Input` and `State` dependencies ......
Read more >
plotly.graph_objects.Figure — 5.11.0 documentation
Determines whether or not a layout width or height that has been left undefined by the user is initialized on each relayout. Note...
Read more >
Python Figure Reference: Single-Page - Plotly
Figures are represented as trees with named nodes called "attributes". The root node of the tree has three top-level attributes: data , layout...
Read more >
Part 4. Interactive Graphing and Crossfiltering - Dash Plotly
Graphs can be inputs as well as outputs: bind interactivity to the Dash `Graph` component whenever you hover, click, or select points on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found