Skip to content

Commit 432fa10

Browse files
committed
load up widget.js code on import
1 parent 9b812f3 commit 432fa10

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

plotly/widgets/graph_widget.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
from IPython.utils.traitlets import Unicode
88
from IPython.display import Javascript, display
99

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

1222
class Graph(widgets.DOMWidget):
@@ -27,13 +37,6 @@ def __init__(self, graph_url, **kwargs):
2737
--------
2838
GraphWidget('https://plot.ly/~chris/3375')
2939
"""
30-
directory = os.path.dirname(os.path.realpath(__file__))
31-
js_widget_file = os.path.join(directory, 'graphWidget.js')
32-
with open(js_widget_file) as f:
33-
js_widget_code = f.read()
34-
35-
display(Javascript(js_widget_code))
36-
3740
super(Graph, self).__init__(**kwargs)
3841

3942
# TODO: Validate graph_url

0 commit comments

Comments
 (0)