Jupyter / Jupyterlab / notebook
Overview
"Jupyter" is a loose acronym meaning Julia, Python, and R.
Components
- Kernels
- Dashboard
Commands
The Jupyter Notebook has two different keyboard input modes.
-
Edit mode allows you to type code or text into a cell and is indicated by a green cell border.
-
Command mode binds the keyboard to notebook level commands and is indicated by a grey cell border with a blue left margin.
# for running django shell on jupyter notebook
pip install jupyter
pip install django-extensions
python manage.py shell_plus --notebook
python manage.py shell_plus --notebook & #background
# Launching Jupyter Notebook App
jupyter notebook
jupyter notebook --port=5555
jupyter notebook list
jupyter notebook stop 8888
# Run jupyter notebook in background
nohup jupyter notebook &
# Run terminal commands inside jupyter notebook
!pip install enum34
!pip install -U pybrain #For installing packages from cell
Shortcuts
Command Mode (pressEscto enable)
F: find and replace
Shift + Enter ⇧↩: run cell, select below
Ctrl + Enter ⌃↩: run selected cells
⌥↩: run cell and insert below
⌘S: Save and Checkpoint
S: Save and Checkpoint
H: show keyboard shortcuts
Y: change cell to code
M: change cell to markdown
A: insert cell above
B: insert cell below
D, D: delete selected cells
Z: undo cell deletion
L: toggle line numbers
O: toggle output of selected cells
Edit Mode (press Enter to enable)
Jupyterlab
m - markdown
y - code
c - copy
x - cut
v - paste
z - undo
shift z - redo
dd - delete
10 Things about Jupyter Notebook
- Themes (jupyter-themes, oceans16, jupyter-themer)
- Extensions (nb_extensions)
- split cells
- limit output
- snippets
- magics (%lsmagic - show all the built-in magic available)
- write latex
- pdb
- bash script
Magics in Jupyter (magic commands)
1. Line magic (%
)
Operate on single line of input
2. Cell magic (%%
)
Operate on multiple lines of input
3. Commands
%magic for help on magic
%lsmagic for list of magic available
# writes all the code in the cell to a python package
%writefile tensorboard.py
# appends the code in the cell to a file
%writefile --append tensorboard.py
%%time #measure execution time
Code
# For render HTML inside notebook output cell
from IPython.core.display import display, HTML
display(HTML(html_text))
Hide all code
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
References
- https://www.datacamp.com/community/tutorials/tutorial-jupyter-notebook
- https://www.dataquest.io/blog/advanced-jupyter-notebooks-tutorial
- https://towardsdatascience.com/speed-up-jupyter-notebooks-20716cbe2025
- https://towardsdatascience.com/how-to-effortlessly-optimize-jupyter-notebooks-e864162a06ee
- https://blog.dominodatalab.com/lesser-known-ways-of-using-notebooks
Jupyter Extensions
Interact Jupyter
The interact function (ipywidgets.interact) automatically creates user interface (UI) controls for exploring code and data interactively.
Using button
interact_manual(f, x=['apples','oranges']);
Dropdown
interact(f, x=['apples','oranges']);
https://ipywidgets.readthedocs.io/en/stable/index.html
https://ipywidgets.readthedocs.io/en/stable/examples/Using%20Interact.html
https://github.com/jupyterlab/jupyterlab/issues/4930
Jupyter Lab
JupyterLab is the next-generation user interface for Project Jupyter offering all the familiar building blocks of the classic Jupyter Notebook (notebook, terminal, text editor, file browser, rich outputs, etc.) in a flexible and a more powerful user interface.The basic idea of the Jupyter Lab is to bring all the building blocks that are in the classic notebook, plus some new stuff, under one roof.
pip install --upgrade jupyterlab
jupyter lab build
jupyter lab
jupyter lab --ip=0.0.0.0 --allow-root
jupyter lab --core-mode
start.sh jupyter lab --LabApp.token='jitCkhLMxSgw1mJp' --LabApp.ip='0.0.0.0' --LabApp.allow_root=True --LabApp.MappingKernelManager.cull_idle_timeout=600 --LabApp.MappingKernelManager.cull_interval=60 --LabApp.MappingKernelManager.cull_connected=True
c.NotebookApp.nbserver_extensions = {}
NotebookApp.max_buffer_size = your desired value
jupyter labextension list
Extensions
- https://github.com/lckr/jupyterlab-variableInspector
- https://github.com/jupyterlab/jupyterlab-git
- https://github.com/jupyterlab/jupyterlab-toc