Created
March 10, 2018 02:10
-
-
Save sauln/b4e5847d503f5760ab8c8683a5119ba3 to your computer and use it in GitHub Desktop.
Minimal Jupyter notebook example showing strange inception bug
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import IPython\n", | |
"import html\n", | |
"\n", | |
"raw_html = '''\n", | |
"<html>\n", | |
"\n", | |
"<head>\n", | |
"\n", | |
"<h1>Some HTML in an iframe</h1>\n", | |
"\n", | |
"<div id=\"control\">\n", | |
" <a href=\"#\"><small>[-]</small></a>\n", | |
"</div>\n", | |
"\n", | |
"</body>\n", | |
"</html>\n", | |
"\n", | |
"'''\n", | |
"\n", | |
"# In my actual case, this JS runs when the [-] is clicked. It is not necessary to reproduce this issue though.\n", | |
"# d3.select(\"#meta_control\").on(\"click\", function() {\n", | |
"# d3.select(\"#meta\").style(\"display\", \"none\");\n", | |
"# });\n", | |
" \n", | |
"iframe = f'''<iframe srcdoc=\"{html.escape(raw_html)}\" width=100%% height=250></iframe>'''\n", | |
"IPython.display.HTML(iframe)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"with open(\"test.html\", \"w\") as f:\n", | |
" f.write(raw_html)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"iframe = '<iframe src=test.html width=100%% height=250></iframe>'\n", | |
"IPython.core.display.display(IPython.core.display.HTML(iframe))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"IPython.core.display.display(IPython.display.IFrame('test.html', width=700, height=250))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment