Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream.write raises error in plotly 3.1.0 #1108

Closed
Kully opened this issue Aug 13, 2018 · 5 comments
Closed

stream.write raises error in plotly 3.1.0 #1108

Kully opened this issue Aug 13, 2018 · 5 comments
Labels
bug something broken

Comments

@Kully
Copy link
Contributor

Kully commented Aug 13, 2018

A simple streaming example that was working in Plotly 2.2 now does not work in 3.1.0+

import time
import plotly.plotly as py
from plotly.graph_objs import Data, Scatter, Stream, Bar

stream_id = '3luati1sxe'


py.plot(Data([Bar(x=[1], y=[1], stream=Stream(token=stream_id, maxpoints=60))]))

stream = py.Stream(stream_id) # Initialize a stream object
stream.open() # Open the stream

for i in range(1000):
    m = stream.write(dict(x=[i+2], y=[5]))
    print "i: ", i
    time.sleep(2)
    print "Sent"

results in the validation error

ValueError: The 'type' property of scatter is read-only

Changing m = stream.write(dict(x=[i+2], y=[5])) to m = stream.write(Bar(x=[i+2], y=[5])) bypasses the problem, allowing the script to run and print the statements. But the figure is not appending to its data, but replacing each Bar trace that is added as evidenced by the (i)plot that updates.

cc @jonmmease @tarzzz

@Kully Kully added the bug something broken label Aug 13, 2018
@jonmmease
Copy link
Contributor

In 3.1.1 I made a change allowing the 'type' property of a trace to be set as long as it's set to the correct value. When I try this example on master I get a different error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-747009c91fc0> in <module>()
     12 
     13 for i in range(1000):
---> 14     m = stream.write(dict(x=[i+2], y=[5]))
     15     print("i: ", i)
     16     time.sleep(2)

~/Plotly/repos/plotly.py/plotly/plotly/plotly.py in write(self, trace, layout, reconnect_on)
    692                         "Here's why:\n\n{0}".format(err)
    693                     )
--> 694         del stream_object['type']
    695 
    696         if layout is not None:

AttributeError: __delitem__

This error can be fixed by converting the trace to a dict before removing the 'type' key. But as you observed, even in this case the data is replaced, not appended to on each write.

The reason that the data is overwriting rather than appending seems to be related to the fact that the new x and y values are lists rather than scalar values. If I remove the trace validation and change the write line to m = stream.write(dict(x=i+2, y=5)) the data is appended.

I suspect the version 2 would also have the overwriting behavior if x and y are set to lists.

Is this something you could look into @Kully or @tarzzz ? Seems it may require some insight into what the plot.ly stream service is doing.

@gnthibault
Copy link

gnthibault commented Aug 28, 2018

I am also experimenting the very same issue. @Kully workaround resulted in the same behaviour (unwanted) for Scatter instead of Bar.

I also tried to include a 'type' entry in the input dictionary that could have solved the issue.
And then I discovered that streaming is no more supported on the free version of plotly:
https://help.plot.ly/streaming/

@jonmmease
Copy link
Contributor

@gnthibault BTW, what is your streaming use case? The cloud-based streaming is being deprecated, but it is possible to update existing figures using a FigureWidget in a notebook or using Dash in the web browser.

At the moment with FigureWidget you would need to update all of the data for each update, but I'm interested in adding a more efficient append/stream option in the future

@gnthibault
Copy link

Thanks for enquiring. I finally found what I was looking for. I now use a Dash app, in which some browser-side code triggers a callback at regular interval, that I use to do some query in a database.
It is perfect for the dashboard application I am trying to write.

@jonmmease
Copy link
Contributor

Fixed in #1145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

3 participants