JupyterLab¶
Deep dive into the JupyterLab configuration and features.
Overview¶
JupyterLab is the next-generation interface for Jupyter notebooks. In DataSci Homelab, it's configured with:
- Python and R kernels
- Git integration
- Notebook diffing
- Interactive widgets
- Persistent package storage
Accessing JupyterLab¶
Authentication: Enter the token from your JUPYTER_TOKEN in .env
Available Kernels¶
Python 3¶
The default Python kernel with the full scientific stack.
R¶
Use R directly in Jupyter via IRkernel.
Package Management¶
Python Packages¶
# Install in a notebook cell
!pip install packagename
# Or with specific version
!pip install packagename==1.2.3
Packages are installed to ~/.local/lib/python3.x/site-packages/, which is volume-mounted for persistence.
R Packages (in R Kernel)¶
Uses the same R library as RStudio Server.
Verifying Installation¶
Extensions¶
Pre-installed Extensions¶
| Extension | Description |
|---|---|
jupyterlab-git | Git integration panel |
nbdime | Notebook diffing and merging |
ipywidgets | Interactive widgets |
Git Extension¶
Access via the Git icon in the left sidebar:
- Clone repositories
- Stage/unstage changes
- Commit with messages
- Push/pull to remotes
- View history and diffs
Using Widgets¶
import ipywidgets as widgets
slider = widgets.IntSlider(
value=50,
min=0,
max=100,
description='Value:'
)
display(slider)
Working with Files¶
File Browser¶
The left sidebar file browser shows:
/home/rstudio/- Your home directory/data/- Shared data directory
Uploading Files¶
- Click the upload button in the file browser
- Or drag-and-drop files directly
Downloading Files¶
Right-click on any file → Download
Data Science Workflows¶
Loading Data¶
import pandas as pd
# From CSV
df = pd.read_csv('/data/myfile.csv')
# From shared directory
df = pd.read_csv('/data/shared/dataset.csv')
# From Parquet (fast!)
df = pd.read_parquet('/data/large_dataset.parquet')
Visualization¶
Database Connections¶
from sqlalchemy import create_engine
import pandas as pd
# PostgreSQL
engine = create_engine('postgresql://user:pass@host:5432/dbname')
# Query to DataFrame
df = pd.read_sql("SELECT * FROM table", engine)
# DuckDB (embedded)
import duckdb
con = duckdb.connect('mydata.duckdb')
df = con.execute("SELECT * FROM table").df()
R-Python Integration¶
Use rpy2 to mix R and Python in the same notebook:
Quarto in Jupyter¶
Create Quarto documents from Jupyter notebooks:
Method 1: Convert Notebook¶
Method 2: Native Quarto¶
Create .qmd files and open them in JupyterLab's text editor, then render:
Keyboard Shortcuts¶
Command Mode (Blue border)¶
| Key | Action |
|---|---|
Enter | Edit mode |
A | Insert cell above |
B | Insert cell below |
D D | Delete cell |
M | Change to Markdown |
Y | Change to Code |
Shift+Enter | Run and select below |
Ctrl+Enter | Run cell |
Edit Mode (Green border)¶
| Key | Action |
|---|---|
Esc | Command mode |
Tab | Autocomplete |
Shift+Tab | Show signature |
Ctrl+Shift+- | Split cell |
Configuration¶
JupyterLab Settings¶
Access via Settings → Settings Editor
Common customizations:
- Theme (dark/light)
- Font size
- Auto-save interval
- Keyboard shortcuts
Server Configuration¶
The server is configured via /etc/jupyter/jupyter_server_config.py:
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
c.ServerApp.allow_origin = '*'
Tips & Tricks¶
Magic Commands¶
# Time a cell
%%time
expensive_operation()
# Time multiple runs
%%timeit
operation()
# Run shell commands
!ls -la
# Environment variables
%env MY_VAR=value
# Load external scripts
%run script.py
Rich Output¶
Autoreload¶
Troubleshooting¶
Kernel Not Starting¶
# Check kernel list
docker-compose exec homelab jupyter kernelspec list
# Reinstall Python kernel
docker-compose exec homelab python -m ipykernel install --user
# Reinstall R kernel
docker-compose exec homelab Rscript -e "IRkernel::installspec()"
Token Not Working¶
# Check the configured token
docker-compose exec homelab jupyter server list
# Or check logs
docker-compose logs homelab | grep token
Extension Not Working¶
# List extensions
docker-compose exec homelab jupyter labextension list
# Rebuild JupyterLab
docker-compose exec homelab jupyter lab build
Notebook Won't Save¶
Check permissions:
If permissions are wrong: