1
1
from collections import deque
2
2
import json
3
3
import os
4
+ import uuid
4
5
5
6
# TODO: protected imports?
6
7
from IPython .html import widgets
9
10
10
11
import plotly
11
12
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
+
12
23
__all__ = None
13
24
25
+
14
26
class Graph (widgets .DOMWidget ):
15
27
"""An interactive Plotly graph widget for use in IPython
16
28
Notebooks.
@@ -32,13 +44,6 @@ def __init__(self, graph_url, **kwargs):
32
44
--------
33
45
GraphWidget('https://plot.ly/~chris/3375')
34
46
"""
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
-
42
47
super (Graph , self ).__init__ (** kwargs )
43
48
44
49
# TODO: Validate graph_url
@@ -95,6 +100,7 @@ def _handle_outgoing_message(self, message):
95
100
self ._clientMessages .append (message )
96
101
else :
97
102
message ['graphId' ] = self ._graphId
103
+ message ['uid' ] = str (uuid .uuid4 ())
98
104
self ._message = json .dumps (message )
99
105
100
106
def on_click (self , callback , remove = False ):
0 commit comments