Quick Summary: In this practical article in Spanish, you'll see three popular alternatives for creating dashboards and reports in Python β Streamlit, Dash y Bokeh β with ready-to-run code examples, step-by-step deployment instructions (including CI/CD with GitHub Actions), a short guide for publishing on Dev.to, and an English script for your presentation video (β€5 min). π
π§ Γndice
- Why use these tools?
- Streamlit β mini example + simple deploy
- Dash (Plotly) β example, Docker and CI/CD to Cloud Run
- Bokeh β example and deployment notes (websockets)
- Repo structure and requirements.txt
- GitHub Actions: pipeline (tests β build β deploy)
1) Why use these tools? π€
- Streamlit: ultra-fast for interactive prototypes and demos. Ideal for data scientists. β
- Dash: powerful when you need complex components and fine control (Plotly + Flask). π
- Bokeh: very good for interactive visualizations and apps that require a server (Bokeh Server). ποΈ
Each tool has trade-offs in ease vs control vs scalability β in this article you'll see minimal examples and how to get them to the cloud.
2) Streamlit β minimal example
Archivo: streamlit_app.py
# streamlit_app.py
import streamlit as st
import pandas as pd
import altair as alt
st.title('Demo: Streamlit - Sales')
df = pd.DataFrame({
'category': ['A', 'B', 'C', 'A', 'B', 'C'],
'sales': [10, 15, 7, 12, 9, 20]
})
sel = st.selectbox('Select category', ['All'] + df['category'].unique().tolist())
if sel != 'All':
df = df[df['category'] == sel]
chart = alt.Chart(df).mark_bar().encode(
x='category',
y='sales'
)
st.altair_chart(chart, use_container_width=True)
Run locally:
pip install streamlit pandas altair
streamlit run streamlit_app.py
Deployment tip: The fastest way is to use Streamlit Community Cloud (direct connection with GitHub: you upload your repo and deploy it from share.streamlit.io
).
3) Dash (Plotly) β example + Docker + CI/CD (Cloud Run)
File: app.py
# app.py
import os
from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd
# Example data
df = pd.DataFrame({'x': [1, 2, 3, 4], 'y': [10, 5, 8, 12]})
fig = px.line(df, x='x', y='y', title='Dash Example')
app = Dash(__name__)
server = app.server # exposes the WSGI app for Gunicorn
app.layout = html.Div([
html.H1('Dash - Demo'),
dcc.Graph(figure=fig)
])
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 8050)))
requirements.txt (example):
dash
pandas
plotly
gunicorn
Dockerfile (para Cloud Run u otros servicios)
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Gunicorn runs the WSGI server exposed in `server`
CMD ["gunicorn", "--bind", ":$PORT", "--workers", "1", "--threads", "8", "--timeout", "0", "app:server"]
GitHub Actions β Build & Deploy to Google Cloud Run
Save this workflow to .github/workflows/deploy-cloudrun.yml
:
name: CI/CD - Cloud Run
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure GCloud
uses: google-github-actions/setup-gcloud@v1
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Build and push image (Cloud Build)
run: |
gcloud builds submit --tag gcr.io/${{ secrets.GCP_PROJECT_ID }}/dash-app:$GITHUB_SHA
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: dash-app
image: gcr.io/${{ secrets.GCP_PROJECT_ID }}/dash-app:$GITHUB_SHA
region: us-central1
β
What it does: On every push to main
, the workflow builds the image, uploads it to Google Container Registry, and deploys a new revision to Cloud Run.
4) Bokeh β minimal example and deployment notes
File: main.py
(Bokeh server)
# main.py
from bokeh.plotting import figure
from bokeh.io import curdoc
p = figure(title='Bokeh demo')
p.line([1, 2, 3, 4], [3, 7, 8, 5])
curdoc().add_root(p)
Run locally (Bokeh server):
pip install bokeh
bokeh serve --show main.py
Deployment notes:
- Bokeh uses websockets (Bokeh Server). When deploying, ensure your service supports timeouts and websocket connections.
- Typical strategy: create a Dockerfile with
bokeh serve --port $PORT --allow-websocket-origin='*' main.py
and deploy to Cloud Run (or similar). - If using Cloud Run, configure a higher timeout for long connections.
5) Recommended structure
my-dashboard/
ββ streamlit_app.py
ββ app.py # dash
ββ main.py # bokeh
ββ requirements.txt
ββ Dockerfile # for dash/bokeh if using container
ββ .github/
ββ workflows/
ββ deploy-cloudrun.yml
6) GitHub Actions: suggested pipeline (details)
-
Test β Run
pytest
or quick checks (flake8
,mypy
). -
Build β Build Docker image or run
gcloud builds submit
. -
Deploy β
gcloud run deploy
or usegoogle-github-actions/deploy-cloudrun
.
π GitHub Repository
The full code with Streamlit, Dash, and Bokeh examples, along with the Dockerfile
and CI/CD workflows with GitHub Actions, is available in the following repository:
Top comments (0)