Skip to content

Instantly share code, notes, and snippets.

@sametz
Last active July 22, 2019 14:34
Show Gist options
  • Save sametz/5d846cf121532adb5af4bbee2eba4b9b to your computer and use it in GitHub Desktop.
Save sametz/5d846cf121532adb5af4bbee2eba4b9b to your computer and use it in GitHub Desktop.
Hide code in Jupyter notebook
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import HTML"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<script>\n",
"code_show=true; \n",
"function code_toggle() {\n",
" if (code_show){\n",
" $('div.input').hide();\n",
" } else {\n",
" $('div.input').show();\n",
" }\n",
" code_show = !code_show\n",
"} \n",
"$( document ).ready(code_toggle);\n",
"</script>\n",
"The raw code for this IPython notebook is by default hidden for easier reading. As you scroll through code cell,\n",
"they appear as empty cells\n",
"with a blue left-side edge\n",
"To toggle on/off the raw code, click <a href=\"javascript:code_toggle()\">here</a>."
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"HTML('''<script>\n",
"code_show=true; \n",
"function code_toggle() {\n",
" if (code_show){\n",
" $('div.input').hide();\n",
" } else {\n",
" $('div.input').show();\n",
" }\n",
" code_show = !code_show\n",
"} \n",
"$( document ).ready(code_toggle);\n",
"</script>\n",
"The raw code for this IPython notebook is by default hidden for easier reading. As you scroll through code cell,\n",
"they appear as empty cells\n",
"with a blue left-side edge\n",
"To toggle on/off the raw code, click <a href=\"javascript:code_toggle()\">here</a>.''')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, World, from the hidden code cell!\n"
]
}
],
"source": [
"print('Hello, World, from the hidden code cell!')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:chem333] *",
"language": "python",
"name": "conda-env-chem333-py"
},
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment