Skip to content

load up widget.js code on import #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions plotly/widgets/graph_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@

import plotly

# 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):
"""An interactive Plotly graph widget for use in IPython
Notebooks.
Expand All @@ -29,13 +40,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
Expand Down