Deploy Jupyter with Bantam CLI
Share your data science notebooks as static websites
Quick start:
# Build your Jupyter app
jupyter nbconvert --to html *.ipynb
# Deploy it
bantam deploy .
Quick Start
Convert notebook to HTML
Export your notebook as static HTML
jupyter nbconvert --to html notebook.ipynb
Deploy with Bantam
Your notebook is now online!
bantam deploy notebook.html
Framework Details
Batch Conversion
Convert multiple notebooks at once:
Convert all notebooks in directory:
# Convert all notebooks
jupyter nbconvert --to html *.ipynb
# Convert with custom template
jupyter nbconvert --to html --template classic *.ipynb
# Create index page
echo '<h1>My Notebooks</h1>' > index.html
for f in *.html; do
echo "<a href='$f'>$f</a><br>" >> index.html
done
Custom Templates
Use templates for better presentation:
Available templates:
# Built-in templates
jupyter nbconvert --to html --template lab notebook.ipynb
jupyter nbconvert --to html --template classic notebook.ipynb
jupyter nbconvert --to html --template reveal notebook.ipynb
# Custom CSS
jupyter nbconvert --to html --template basic --HTMLExporter.extra_template_basedirs=templates notebook.ipynb
Hide code cells for reports:
# Using tags
jupyter nbconvert --to html \
--TagRemovePreprocessor.remove_cell_tags='{"hide-code"}' \
--TagRemovePreprocessor.remove_input_tags='{"hide-input"}' \
notebook.ipynb
Output Structure
Jupyter nbconvert creates self-contained HTML:
- All CSS embedded in HTML file
- Images encoded as base64
- JavaScript for syntax highlighting
- MathJax for LaTeX rendering
- Interactive widget states preserved
Advanced Usage
Custom Domain
Deploy directly to your own domain
bantam deploy ./dist --domain myapp.com
Permanent Deployment
Keep your site online forever (requires login)
bantam deploy ./dist --permanent
Custom Expiry
Set how long your deployment stays online
bantam deploy ./dist --expiry-days 7
Custom Subdomain
Choose your own subdomain on bantam.site
bantam deploy ./dist --subdomain my-project
CI/CD Integration
Add Bantam to your continuous deployment pipeline:
# GitHub Actions example
- name: Deploy to Bantam
run: |
npm install -g @bantamhq/cli
bantam login --token ${{ secrets.BANTAM_TOKEN }}
bantam deploy ./dist --domain myapp.com --permanent
Common Issues & Solutions
Quick fixes for deployment challenges
01.Images not showing in HTML?
Ensure images are embedded:
# Embed images in HTML
jupyter nbconvert --to html --embed-images notebook.ipynb
# Or use execute to regenerate outputs
jupyter nbconvert --to html --execute notebook.ipynb
02.LaTeX math not rendering?
MathJax should be included by default. For offline viewing:
# Download MathJax for offline use
jupyter nbconvert --to html --mathjax-url=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js notebook.ipynb
03.Want to hide code but show outputs?
Use cell tags or preprocessing:
# In notebook, tag cells with "hide-input"
# View > Cell Toolbar > Tags
# Then convert
jupyter nbconvert --to html --TagRemovePreprocessor.enabled=True --TagRemovePreprocessor.remove_input_tags='["hide-input"]' notebook.ipynb
Or hide all code cells:
jupyter nbconvert --to html --no-input notebook.ipynb
04.Creating a notebook portfolio?
Build a simple portfolio site:
#!/bin/bash
# convert_all.sh
# Convert all notebooks
for nb in *.ipynb; do
jupyter nbconvert --to html "$nb"
done
# Create index
cat > index.html << EOF
<!DOCTYPE html>
<html>
<head>
<title>My Data Science Portfolio</title>
<style>
body { font-family: Arial; max-width: 800px; margin: 0 auto; padding: 20px; }
.notebook { margin: 20px 0; padding: 15px; border: 1px solid #ddd; }
</style>
</head>
<body>
<h1>Data Science Portfolio</h1>
EOF
# Add links to notebooks
for html in *.html; do
if [ "$html" != "index.html" ]; then
name=${html%.html}
echo " <div class='notebook'><a href='$html'>$name</a></div>" >> index.html
fi
done
echo "</body></html>" >> index.html
# Deploy everything
bantam deploy .
05.Interactive widgets not working?
Interactive widgets become static in HTML. For interactivity, consider:
# Option 1: Use Voilà for dashboard-like apps
pip install voila
voila notebook.ipynb --no-browser
# Option 2: Convert to reveal.js presentation
jupyter nbconvert --to slides notebook.ipynb
# Option 3: Export widget state
jupyter nbconvert --to html --ExecutePreprocessor.store_widget_state=True notebook.ipynb