Skip to content

Instantly share code, notes, and snippets.

@martindurant
Created July 18, 2017 19:50
Show Gist options
  • Save martindurant/b04e0e3105202d85ee7b4fd7481adb1f to your computer and use it in GitHub Desktop.
Save martindurant/b04e0e3105202d85ee7b4fd7481adb1f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hide my cells!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world!\n"
]
}
],
"source": [
"# code with output\n",
"print(\"Hello world!\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a2ea9d965b37499689a2b67399dda4c3"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"$('div.prompt.input_prompt').hide()\n",
"$('div.inner_cell').hide()"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"$('div.prompt.input_prompt').show()\n",
"$('div.inner_cell').show()"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import Javascript\n",
"j1 = Javascript(\"\"\"$('div.prompt.input_prompt').hide()\n",
"$('div.inner_cell').hide()\"\"\")\n",
"j2 = Javascript(\"\"\"$('div.prompt.input_prompt').show()\n",
"$('div.inner_cell').show()\"\"\")\n",
"\n",
"from IPython.display import Javascript, display\n",
"from ipywidgets import widgets\n",
"shown = True\n",
"\n",
"def showhide(ev):\n",
" global shown\n",
" if shown:\n",
" display(j1)\n",
" else:\n",
" display(j2)\n",
" shown = not shown\n",
"\n",
"button = widgets.Button(description=\"ShowHide\")\n",
"button.on_click(showhide)\n",
"display(button)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"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.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment