diff --git a/lightning/main.py b/lightning/main.py index 8a1053c..769b812 100644 --- a/lightning/main.py +++ b/lightning/main.py @@ -49,10 +49,12 @@ def enable_ipython(self, **kwargs): self.ipython_enabled = True ip = get_ipython() formatter = ip.display_formatter.formatters['text/html'] - formatter.for_type(Visualization, lambda viz, kwds=kwargs: viz.get_html()) + formatter.for_type(Visualization, lambda viz, kwds=kwargs: viz.get_pym_html()) r = requests.get(self.get_ipython_markup_link(), auth=self.auth) + display(Javascript(r.text)) + r = requests.get("https://cdnjs.cloudflare.com/ajax/libs/pym/0.4.5/pym.js") display(Javascript(r.text)) def disable_ipython(self): diff --git a/lightning/visualization.py b/lightning/visualization.py index e80e35a..cc0a8c7 100644 --- a/lightning/visualization.py +++ b/lightning/visualization.py @@ -1,5 +1,6 @@ import requests import json +import uuid import webbrowser @@ -16,7 +17,6 @@ def __init__(self, session=None, json=None, auth=None): self.comm_handlers = {} self.comm.on_msg(self._handle_comm_message) - def _format_url(self, url): if not url.endswith('/'): url += '/' @@ -68,6 +68,16 @@ def get_html(self): r = requests.get(self.get_embed_link(), auth=self.auth) return r.text + def get_pym_link(self): + return self._format_url(self.get_permalink() + '/pym') + + def get_pym_html(self): + r = self.get_pym_link() + uid = uuid.uuid4().hex + html = '
' % uid + js = '' % (uid, r) + return html + js + def open(self): webbrowser.open(self.session.host + '/visualizations/' + str(self.id) + '/') @@ -75,7 +85,6 @@ def delete(self): url = self.get_permalink() return requests.delete(url) - def on(self, event_name, handler): if self.session.lgn.ipython_enabled: @@ -84,7 +93,6 @@ def on(self, event_name, handler): else: raise Exception('The current implementation of this method is only compatible with IPython.') - def _handle_comm_message(self, message): # Parsing logic taken from similar code in matplotlib message = json.loads(message['content']['data']) @@ -92,7 +100,6 @@ def _handle_comm_message(self, message): if message['type'] in self.comm_handlers: self.comm_handlers[message['type']](message['data']) - @classmethod def create(cls, session=None, data=None, images=None, type=None, options=None):