From 432fa10042a09fe39cd408faa950edd47047c8cd Mon Sep 17 00:00:00 2001 From: Chris P Date: Tue, 6 Jan 2015 18:01:00 -0500 Subject: [PATCH] load up widget.js code on import --- plotly/widgets/graph_widget.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plotly/widgets/graph_widget.py b/plotly/widgets/graph_widget.py index 2ac5c504b40..716905d2e47 100644 --- a/plotly/widgets/graph_widget.py +++ b/plotly/widgets/graph_widget.py @@ -7,6 +7,16 @@ from IPython.utils.traitlets import Unicode from IPython.display import Javascript, display +# Load JS widget code +# No officially recommended way to do this in any other way +# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html +directory = os.path.dirname(os.path.realpath(__file__)) +js_widget_file = os.path.join(directory, 'graphWidget.js') +with open(js_widget_file) as f: + js_widget_code = f.read() + +display(Javascript(js_widget_code)) + __all__ = None class Graph(widgets.DOMWidget): @@ -27,13 +37,6 @@ def __init__(self, graph_url, **kwargs): -------- GraphWidget('https://plot.ly/~chris/3375') """ - directory = os.path.dirname(os.path.realpath(__file__)) - js_widget_file = os.path.join(directory, 'graphWidget.js') - with open(js_widget_file) as f: - js_widget_code = f.read() - - display(Javascript(js_widget_code)) - super(Graph, self).__init__(**kwargs) # TODO: Validate graph_url