Skip to content

Commit b405404

Browse files
committed
Merge branch 'widgets' into widgets-update-syntax
Conflicts: plotly/widgets/graph_widget.py
2 parents 67e2b0c + 0e459c0 commit b405404

File tree

5 files changed

+49
-24
lines changed

5 files changed

+49
-24
lines changed

plotly/plotly/plotly.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,15 @@ class Stream:
406406
Stream example:
407407
# Initialize a streaming graph
408408
# by embedding stream_id's in the graph's traces
409-
>>> stream_id = "your_stream_id" # See {plotly_domain}/settings
410-
>>> py.plot(Data([Scatter(x=[],
411-
y=[],
412-
stream=dict(token=stream_id, maxpoints=100))])
409+
import plotly.plotly as py
410+
from plotly.graph_objs import Data, Scatter, Stream
411+
stream_id = "your_stream_id" # See {plotly_domain}/settings
412+
py.plot(Data([Scatter(x=[], y=[],
413+
stream=Stream(token=stream_id, maxpoints=100))]))
413414
# Stream data to the import trace
414-
>>> stream = Stream(stream_id) # Initialize a stream object
415-
>>> stream.open() # Open the stream
416-
>>> stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
415+
stream = Stream(stream_id) # Initialize a stream object
416+
stream.open() # Open the stream
417+
stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
417418
"""
418419

419420
@utils.template_doc(**tools.get_config_file())

plotly/widgets/graphWidget.js

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plotly/widgets/graph_widget.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from collections import deque
22
import json
33
import os
4-
import random
5-
import string
4+
import uuid
65

76
# TODO: protected imports?
87
from IPython.html import widgets
@@ -11,15 +10,29 @@
1110

1211
import plotly
1312

13+
# Load JS widget code
14+
# No officially recommended way to do this in any other way
15+
# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html
16+
directory = os.path.dirname(os.path.realpath(__file__))
17+
js_widget_file = os.path.join(directory, 'graphWidget.js')
18+
with open(js_widget_file) as f:
19+
js_widget_code = f.read()
20+
21+
display(Javascript(js_widget_code))
22+
1423
__all__ = None
1524

25+
1626
class Graph(widgets.DOMWidget):
1727
"""An interactive Plotly graph widget for use in IPython
1828
Notebooks.
1929
"""
2030
_view_name = Unicode('GraphView', sync=True)
2131
_message = Unicode(sync=True)
2232
_graph_url = Unicode(sync=True)
33+
_plotly_domain = Unicode(
34+
sync=True, default_value=plotly.plotly.get_config()['plotly_domain']
35+
)
2336

2437
def __init__(self, graph_url, **kwargs):
2538
"""Initialize a plotly graph object.
@@ -31,13 +44,6 @@ def __init__(self, graph_url, **kwargs):
3144
--------
3245
GraphWidget('https://plot.ly/~chris/3375')
3346
"""
34-
directory = os.path.dirname(os.path.realpath(__file__))
35-
js_widget_file = os.path.join(directory, 'graphWidget.js')
36-
with open(js_widget_file) as f:
37-
js_widget_code = f.read()
38-
39-
display(Javascript(js_widget_code))
40-
4147
super(Graph, self).__init__(**kwargs)
4248

4349
# TODO: Validate graph_url
@@ -89,13 +95,12 @@ def _handle_registration(self, event_type, callback, remove):
8995
self._handle_outgoing_message(message)
9096

9197
def _handle_outgoing_message(self, message):
92-
message['plotlyDomain'] = plotly.plotly.get_config()['plotly_domain']
93-
message['taskID'] = ''.join([random.choice(string.ascii_letters)
94-
for _ in range(20)])
98+
message['plotlyDomain'] = self._plotly_domain
9599
if self._graphId == '':
96100
self._clientMessages.append(message)
97101
else:
98102
message['graphId'] = self._graphId
103+
message['uid'] = str(uuid.uuid4())
99104
self._message = json.dumps(message)
100105

101106
def on_click(self, callback, remove=False):

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ six==1.8.0
1313

1414
## timezone definitions ##
1515
pytz==2014.9
16+
17+
## 2.6 python dependencies ##
18+
simplejson==3.6.5
19+
ordereddict==1.1

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ def readme():
4040
'plotly/matplotlylib/mplexporter',
4141
'plotly/matplotlylib/mplexporter/renderers'],
4242
package_data={'plotly': ['graph_reference/*.json']},
43-
install_requires=['requests', 'six', 'pytz'],
43+
install_requires=['requests',
44+
'six',
45+
'pytz',
46+
'ordereddict',
47+
'simplejson'],
4448
zip_safe=False)

0 commit comments

Comments
 (0)