2025-06-23 16:58:51 +02:00
# JupyterHub Notebook Viewer
2025-06-17 13:06:48 +02:00
A Flask-based web application for viewing and browsing Jupyter notebooks from a JupyterHub shared directory. Features a responsive web interface with directory navigation, notebook preview, and download capabilities.
2025-06-23 16:58:51 +02:00
## Quick Start
Using Nix (Recommended)
2025-06-17 13:06:48 +02:00
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# Enter development environment
nix develop
# Set up the environment (first time only)
setup-dev
# Start development server
dev-server
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
2025-06-23 16:58:51 +02:00
Using Docker
2025-06-17 13:06:48 +02:00
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# Copy and configure environment
cp .env.example .env
# Edit .env with your settings
# Start with Docker Compose
docker-compose up
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
Manual Installation
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Start the application
python app.py
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
2025-06-23 16:58:51 +02:00
## Configuration
2025-06-17 13:06:48 +02:00
All configuration is done via environment variables, typically in a .env file:
Core Settings
JUPYTERHUB_SHARED_DIR - Path to the shared notebook directory (default: /shared)
APP_TITLE - Application title shown in the interface
Flask Settings
FLASK_HOST - Host to bind to (default: 0.0.0.0)
FLASK_PORT - Port to run on (default: 5000)
FLASK_DEBUG - Enable debug mode (default: True)
FLASK_SECRET_KEY - Secret key for sessions (change in production!)
File Handling
MAX_FILE_SIZE - Maximum file size in bytes (default: 16777216 = 16MB)
NOTEBOOKS_PER_PAGE - Maximum notebooks to show per directory (default: 50)
ALLOWED_EXTENSIONS - Comma-separated list of allowed file extensions (default: .ipynb,.py,.md)
Feature Toggles
ENABLE_DOWNLOAD - Enable file downloads (default: True)
ENABLE_API - Enable JSON API endpoints (default: True)
2025-06-23 16:58:51 +02:00
## Development
2025-06-17 13:06:48 +02:00
With Nix
The project includes a complete Nix flake for reproducible development:
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# Enter development shell
nix develop
# Available commands in the shell:
setup-dev # Set up development environment
dev-server # Start development server with auto-reload
run-tests # Run basic tests
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
With Just
If you have just installed:
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# See all available commands
just
# Common commands
just setup # Set up development environment
just dev # Start development server
just docker-up # Start with Docker
just test # Run tests
just clean # Clean temporary files
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
Manual Development
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# Install dependencies
pip install -r requirements.txt
# Set up environment
cp .env.example .env
# Create sample content
mkdir -p shared
# Add some .ipynb files to shared/
# Start development server
python app.py
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
Docker Deployment
Basic Deployment
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# Build and start
docker-compose up --build
# Run in background
docker-compose up -d
# View logs
docker-compose logs -f
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
With Reverse Proxy
The compose file includes an optional nginx reverse proxy:
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
# Start with proxy
docker-compose --profile with-proxy up
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
2025-06-23 16:58:51 +02:00
## Production Considerations
2025-06-17 13:06:48 +02:00
For production deployment:
Change the secret key: Set FLASK_SECRET_KEY to a secure random value
Disable debug mode: Set FLASK_DEBUG=False
Configure volumes: Mount your actual shared directory
Set up SSL: Configure HTTPS in your reverse proxy
Resource limits: Set appropriate CPU and memory limits in Docker
2025-06-23 16:58:51 +02:00
## API Endpoints
2025-06-17 13:06:48 +02:00
When ENABLE_API=True, the following JSON API endpoints are available:
GET /api/notebooks?dir=< path > - List notebooks and directories
GET / - Main web interface
GET /view/< path > - View notebook as HTML
GET /download/< path > - Download notebook file (if enabled)
2025-06-23 16:58:51 +02:00
## Troubleshooting
2025-06-17 13:06:48 +02:00
Common Issues
"No notebooks found"
Check that JUPYTERHUB_SHARED_DIR points to the correct directory
Ensure the directory contains .ipynb files
Check file permissions
Notebook won't display
Verify the notebook file is valid JSON
Check that nbconvert dependencies are installed
Look for errors in the application logs
Permission denied
Ensure the application has read access to the shared directory
Check Docker volume mounts
2025-06-23 16:58:51 +02:00
## Logs
2025-06-17 13:06:48 +02:00
Application logs are printed to stdout. In Docker:
2025-06-23 16:58:51 +02:00
```bash
2025-06-17 13:06:48 +02:00
docker-compose logs -f notebook-viewer
2025-06-23 16:58:51 +02:00
```
2025-06-17 13:06:48 +02:00
2025-06-23 16:58:51 +02:00
## License
2025-06-17 13:06:48 +02:00
MIT License - see LICENSE file for details.
Architecture