NiceGUI is a fantastic Python framework for creating web-based user interfaces with ease. If you've built a NiceGUI app and want to deploy it without the complexity of managing servers, you're in the right place. In this tutorial, I'll show you how to containerize and deploy your NiceGUI application on Sliplane.
Prerequisites
Before we start, make sure you have:
- A NiceGUI application ready to deploy
- Docker installed on your local machine (for testing)
- A GitHub repository with your NiceGUI code
- A Sliplane account
Step 1: Prepare Your NiceGUI Application
First, let's make sure your NiceGUI app is production-ready. Here's a basic example of a NiceGUI application:
from nicegui import ui
@ui.page('/')
def index():
ui.label('Hello NiceGUI World!')
ui.button('Click me!', on_click=lambda: ui.notify('Button clicked!'))
if __name__ in {"__main__", "__mp_main__"}:
ui.run(host='0.0.0.0', port=8080, reload=False)
Key points for production deployment:
- Set
host='0.0.0.0'
to accept connections from outside the container - Use any port you prefer (Sliplane auto-detects ports)
- Set
reload=False
for production stability - Use the
if __name__
check to prevent issues with container restarts
Step 2: Create the Dockerfile
Create a Dockerfile
in your project root:
FROM zauberzeug/nicegui:latest
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["python", "main.py"]
This Dockerfile:
- Uses the latest official NiceGUI base image (check Docker Hub for specific versions if needed)
- Installs your dependencies from
requirements.txt
- Copies your application code
- Exposes port 8080
- Runs your main application file
Step 3: Create Requirements File
Create a requirements.txt
file with your dependencies:
nicegui
# Add any other dependencies your app needs
# For example:
# pandas
# requests
# matplotlib
Step 4: Add Docker Ignore File
Create a .dockerignore
file to exclude unnecessary files:
__pycache__
*.pyc
*.pyo
*.pyd
.git
.gitignore
README.md
.pytest_cache
.coverage
venv/
env/
.venv/
.env/
Step 5: Test Locally
Before deploying, test your container locally:
# Build the image
docker build -t my-nicegui-app .
# Run the container
docker run -p 8080:8080 my-nicegui-app
Visit http://localhost:8080
to verify your app works correctly in the container.
Step 6: Deploy on Sliplane
Now for the easy part! Here's how to deploy your NiceGUI app on Sliplane:
Sign up for Sliplane (first 2 days free)
Connect your GitHub repository by clicking "Create Service" and selecting your repository
-
Configure your service:
- Service name:
my-nicegui-app
(or your preferred name) - Keep other settings as default (Sliplane auto-detects ports)
- Service name:
Click Deploy and wait about 2-3 minutes
Access your app at
https://my-nicegui-app.sliplane.app
That's it! Your NiceGUI app is now live and accessible worldwide.
Automatic Updates
Whenever you push changes to your GitHub repository, Sliplane automatically rebuilds and deploys your application. No manual intervention required.
Cost Comparison
Platform | Monthly Cost | Features |
---|---|---|
Sliplane Base | €9.00 | 2 vCPU, 2GB RAM, 40GB SSD |
Google Cloud Run | ~$132 | 2 vCPU, 2GB RAM, pay-per-use |
Heroku Standard-2X | $50 | 2 vCPU, 2GB RAM |
DigitalOcean App | $25 | 2 vCPU, 2GB RAM, dedicated |
Sliplane offers excellent value with dedicated resources and no cold starts.
FAQ
Q: Can I run multiple NiceGUI apps on one server?
A: Yes! Sliplane allows unlimited containers per server. Deploy multiple NiceGUI apps and they'll share the server resources.
Q: Does NiceGUI work well in containers?
A: Absolutely. NiceGUI was designed with containerization in mind and works perfectly with Docker.
Q: How do I handle file uploads?
A: Use NiceGUI's built-in upload component and save files to a persistent volume mounted at /data
.
Q: Can I use external APIs?
A: Yes, NiceGUI apps can make HTTP requests to external APIs. Store API keys as environment variables in Sliplane.
Ready to deploy your NiceGUI application? Sign up for Sliplane and get your first 2 days free. No credit card required to start!
Cheers,
Jonas
Top comments (1)
TIL about NiceGUI!