Created
November 9, 2018 14:50
-
-
Save manugarri/bcda8995b96bedeb54e46a4705c60121 to your computer and use it in GitHub Desktop.
widget to display json in jupyter notebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
from IPython.display import display_javascript, display_html, display | |
import json | |
class RenderJSON(object): | |
def __init__(self, json_data): | |
if isinstance(json_data, dict): | |
self.json_str = json.dumps(json_data) | |
else: | |
self.json_str = json | |
self.uuid = str(uuid.uuid4()) | |
def _ipython_display_(self): | |
display_html('<div id="{}" style="height: 600px; width:100%;"></div>'.format(self.uuid), | |
raw=True | |
) | |
display_javascript(""" | |
require(["https://rawgit.com/caldwell/renderjson/master/renderjson.js"], function() { | |
renderjson.set_show_to_level(1) | |
document.getElementById('%s').appendChild(renderjson(%s)) | |
}); | |
""" % (self.uuid, self.json_str), raw=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment