In [1]:
from IPython.display import display, HTML, Javascript
from IPython.html.widgets import ButtonWidget, CheckboxWidget
In [2]:
# instantiate the checkbox used to toggle DOM elements
hide_code = CheckboxWidget(description='Output Only Mode')
def toggle_elements(name, checked):
"""
Hide/Show a list of DOM elements
"""
elements = ['div.input', 'button.close', 'div#header', 'div#menubar', 'div#maintoolbar']
if checked:
display(Javascript(''.join("$('%s').hide();" % e for e in elements)))
display(HTML("<style>div.cell.selected{border: none}</style>"))
else:
display(Javascript(''.join("$('%s').show();" % e for e in elements)))
hide_code.on_trait_change(toggle_elements, 'value')
display(hide_code)
In [3]:
# instantiate a couple of buttons for running/clearing the notebook
run = ButtonWidget(description='Run Notebook')
clear = ButtonWidget(description='Clear Notebook')
def run_below(b):
"""
Execute all the notebook cells below
"""
display(Javascript('IPython.notebook.execute_cells_below()'))
def clear_output(b):
"""
Cell all cell output
"""
display(Javascript('IPython.notebook.clear_all_output()'))
run.on_click(run_below)
clear.on_click(clear_output)
run.set_css("margin-bottom", "5px")
display(run)
display(clear)
In [4]:
# normal notebook starts here
import numpy as np
plt.hist(np.random.randn(10000), color=np.random.rand(3,1), bins=100)
plt.tight_layout(rect=[0, 0, 2.4, 0.8])
plt.show()