Skip to content

Instantly share code, notes, and snippets.

@manugarri
Created November 9, 2018 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manugarri/bcda8995b96bedeb54e46a4705c60121 to your computer and use it in GitHub Desktop.
Save manugarri/bcda8995b96bedeb54e46a4705c60121 to your computer and use it in GitHub Desktop.
widget to display json in jupyter notebook
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