Skip to content

Commit 0e459c0

Browse files
committed
Merge branch 'widgets' of https://github.com/plotly/python-api into widgets
2 parents 4296f5c + 7b5abf3 commit 0e459c0

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import deque
22
import json
33
import os
4+
import uuid
45

56
# TODO: protected imports?
67
from IPython.html import widgets
@@ -9,8 +10,19 @@
910

1011
import plotly
1112

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+
1223
__all__ = None
1324

25+
1426
class Graph(widgets.DOMWidget):
1527
"""An interactive Plotly graph widget for use in IPython
1628
Notebooks.
@@ -32,13 +44,6 @@ def __init__(self, graph_url, **kwargs):
3244
--------
3345
GraphWidget('https://plot.ly/~chris/3375')
3446
"""
35-
directory = os.path.dirname(os.path.realpath(__file__))
36-
js_widget_file = os.path.join(directory, 'graphWidget.js')
37-
with open(js_widget_file) as f:
38-
js_widget_code = f.read()
39-
40-
display(Javascript(js_widget_code))
41-
4247
super(Graph, self).__init__(**kwargs)
4348

4449
# TODO: Validate graph_url
@@ -95,6 +100,7 @@ def _handle_outgoing_message(self, message):
95100
self._clientMessages.append(message)
96101
else:
97102
message['graphId'] = self._graphId
103+
message['uid'] = str(uuid.uuid4())
98104
self._message = json.dumps(message)
99105

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

0 commit comments

Comments
 (0)