Introduction to JupyterLab - π#
Where am I? (JupyterLab Notebook)#
Jupyter is a powerful suite of tools that allows us to do many things.
Jupyter is capable of running Julia, Python and R, as well as some other things.
Cells#
Each box is called a cell.
Two types of Cells#
Text#
Text Cells allow you to add text (via Markdown), which includes tables, images, links, bullet lists, numbered lists, LaTeX, blockquote, among other things.
Table#
| This | is |
|------|------|
| a | table|
This |
is |
---|---|
a |
table |
Image#
Relative Link#

Absolute Link#

Link#
[Attribution](https://www.metmuseum.org/art/collection/search/436535)
Vincent van Gogh / Public domain The Metropolitan Museum of Art, New York - Purchase, The Annenberg Foundation Gift, 1993 - Attribution
Bullet List#
* I am a
* bullet
* list
I am a
bullet
list
Numbered List#
1. I am a
1. numbered
1. list
I am a
numbered
list
LaTeX#
$$e=mc^2$$
Blockquotes#
> This is a blockquote.
This is a blockquote.
Code#
Cells can be run using the Run button βΊ or selecting one of the run options under the Run menu.
Try this out! You can change what is in the cell and rerun the same cell, which is useful for debugging.
2 + 2
4
Your turn: In a new cell, figure out what 5315 + 5618 is.
## remove and type out 5315 + 5618
## then hit the play button
Jupyter β¨ MAGIC β¨#
When using other languages in Jupyter/JupyterLab, we need to designate the cell we are using with this langauge or function. To βactivateβ these language, we need to use β¨ MAGIC β¨. Here are a couple of examples.
HTML#
%%html
<ol>
<li>apple</li>
<li>banana</li>
<li>cookies</li>
</ol>
- apple
- banana
- cookies
SVG#
%%svg
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="steelblue" />
</svg>
R Language#
In Google Colab, you do not need to install anything, but if you are going to do this on your local machine (your computer).
You will need to install a few things first. To do this, open up the Anaconda Prompt (anaconda3) and run the following two commands:
conda install -c r r-essentials
and
conda install -c r rpy2
finally,
%load_ext rpy2.ipython
In a new cell, we can then add our R code and see it working.
%%R
data <- c(1,2,3)
print(data)
Letβs try this out.
# Let's try here!
SQL#
%%capture
!pip install ipython-sql
Whatβs
%%capture
?
%%capture
is another bit of magic that captures the output of the cell and does not print it.
%load_ext sql
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[7], line 1
----> 1 get_ipython().run_line_magic('load_ext', 'sql')
File ~/.local/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2480, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2478 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2479 with self.builtin_trap:
-> 2480 result = fn(*args, **kwargs)
2482 # The code below prevents the output from being displayed
2483 # when using magics with decorator @output_can_be_silenced
2484 # when the last Python token in the expression is a ';'.
2485 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File ~/.local/lib/python3.10/site-packages/IPython/core/magics/extension.py:33, in ExtensionMagics.load_ext(self, module_str)
31 if not module_str:
32 raise UsageError('Missing module name.')
---> 33 res = self.shell.extension_manager.load_extension(module_str)
35 if res == 'already loaded':
36 print("The %s extension is already loaded. To reload it, use:" % module_str)
File ~/.local/lib/python3.10/site-packages/IPython/core/extensions.py:62, in ExtensionManager.load_extension(self, module_str)
55 """Load an IPython extension by its module name.
56
57 Returns the string "already loaded" if the extension is already loaded,
58 "no load function" if the module doesn't have a load_ipython_extension
59 function, or None if it succeeded.
60 """
61 try:
---> 62 return self._load_extension(module_str)
63 except ModuleNotFoundError:
64 if module_str in BUILTINS_EXTS:
File ~/.local/lib/python3.10/site-packages/IPython/core/extensions.py:77, in ExtensionManager._load_extension(self, module_str)
75 with self.shell.builtin_trap:
76 if module_str not in sys.modules:
---> 77 mod = import_module(module_str)
78 mod = sys.modules[module_str]
79 if self._call_load_ipython_extension(mod):
File /usr/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
124 break
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)
File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:1004, in _find_and_load_unlocked(name, import_)
ModuleNotFoundError: No module named 'sql'
%sql sqlite:///exampleDatabase.db
More information can be found here: Jupyter β¨ MAGIC β¨