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.

Should Plotly.restyle throw error(s) when the update object isn't valid?

See original GitHub issue

Consider this setup,

var data = [
  {
    y: ['22.3', '23'],
    x: ['2001-06-11 11:00', '2001-06-11 11:10'],
    line: {
      'width': 2
    },
    uid: '40abaa'
  }
]

var layout = {
  yaxis: {
    title: 'Rate'
  },
  margin: {
    l: 40, b: 40, r: 40, t: 40
  }
}

Plotly.plot('mydiv', data, layout)

This dosen’t work, and clears the plot

var update = {
  x: ['2001-06-15 11:10', '2001-06-15 11:20'],
  y: ['23', '100.3']
}

Plotly.restyle('mydiv', update)

But this is working

var update = {
  y: ['23', '100.3']
}

Plotly.restyle('mydiv', update)

Plotly.restyle is handling two axis data update incorrectly and clears the existing data on the plot.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
etpinardcommented, Mar 29, 2016

@harshjv Your update object should be:

var update = {
  x: [['2001-06-15 11:10', '2001-06-15 11:20']],
  y: [['23', '100.3']]
};

to update the x and y of your single-trace graph.

The restyle syntax works as fellow, the outer array maps to different traces i.e. your above update object mapped '2001-06-15 11:10' to the x in the first (and only) trace of your graph. As x and y need to be linked to an array, the graph is left blank after the update.

So, to update the the x data, you need to nest the update data array.

More info about the restyle syntax here. Unfortunately our docs on restyle are limited at the moment. Our apologies.

That said, one could argue that trying to update x (or y) with a scalar should throw an error. @mdtusz @cldougl thoughts?

2reactions
cldouglcommented, Jan 7, 2016

No initial opposition to throwing an error from me. Regarding docs: we mention wrapping with the outer array in the function reference doc, but I think it could be a bit more clear if we add a codepen example updating data and possibly use x/y data instead of z (it might be a little easier to see/understand the outer array looking at an x array opposed to a z matrix).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Function reference in JavaScript - Plotly
When restyling, you may choose to have the specified changes affect as many traces as desired. The update is given as a single...
Read more >
Plotly update data - javascript - Stack Overflow
The right way is update the data object, instead of new a data object. ... Plotly.restyle is faster than Plotly.redraw and Plotly.newPlot ....
Read more >
plotly - Bountysource
The problem is that the horizontal legend overlaps the x-axis title. ... Should Plotly.restyle throw error(s) when the update object isn't valid? $...
Read more >
17 Server-side linking with shiny
More specifically, because plotly is inherently web-based, it allows for more control over how the graphics update in response to user input (e.g.,...
Read more >
NEWS
When TRUE (the default), the widget's container element is allowed to grow/shrink ... Fixed an issue where map_color() would throw an error on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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