Skip to content

Commit 49498a0

Browse files
committed
Merge pull request #172 from plotly/js-import
load up widget.js code on import
2 parents 695dd28 + f732045 commit 49498a0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

plotly/widgets/graph_widget.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@
99

1010
import plotly
1111

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

24+
1425
class Graph(widgets.DOMWidget):
1526
"""An interactive Plotly graph widget for use in IPython
1627
Notebooks.
@@ -29,13 +40,6 @@ def __init__(self, graph_url, **kwargs):
2940
--------
3041
GraphWidget('https://plot.ly/~chris/3375')
3142
"""
32-
directory = os.path.dirname(os.path.realpath(__file__))
33-
js_widget_file = os.path.join(directory, 'graphWidget.js')
34-
with open(js_widget_file) as f:
35-
js_widget_code = f.read()
36-
37-
display(Javascript(js_widget_code))
38-
3943
super(Graph, self).__init__(**kwargs)
4044

4145
# TODO: Validate graph_url

0 commit comments

Comments
 (0)