DEV Community

Visualization and Dashboard Tools in Python: Streamlit, Dash, and Bokeh (with Code Examples and Cloud Deployment)

Data visualization plays a crucial role in data science, analysis, and interactive application development. To convert data into dynamic visual experiences, Python offers tools that simplify building dashboards and reports without deep web development knowledge. Among these, Streamlit, Dash, and Bokeh stand out, each with unique features, strengths, and use cases.

This article provides an overview of these tools, practical code examples, and guidelines for deploying applications to the cloud, enabling easy access and collaboration.

What Are Streamlit, Dash, and Bokeh?

  • **Streamlit **is a Python library to build interactive web apps quickly with minimal lines of code. It’s ideal for prototyping and small applications thanks to its ease and speed.
  • Dash, created by Plotly, is a more robust and structured framework suited for enterprise applications requiring higher customization and complexity.
  • **Bokeh **focuses on creating interactive, high-performance visualizations, with strong capabilities for detailed and rich visual applications.

Code Examples

import streamlit as st
import pandas as pd
import numpy as np

st.title("Dashboard with Streamlit")

data = pd.DataFrame({
    'A': np.random.randn(100),
    'B': np.random.randn(100)
})

st.line_chart(data)

Enter fullscreen mode Exit fullscreen mode

Dash

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

df = pd.DataFrame({
    "Category": ["A", "B", "C"],
    "Values": [4, 1, 2]
})

fig = px.bar(df, x="Category", y="Values")

app.layout = html.Div([
    html.H1("Dashboard with Dash"),
    dcc.Graph(figure=fig)
])

if __name__ == '__main__':
    app.run_server(debug=True)

Enter fullscreen mode Exit fullscreen mode

Bokeh

from bokeh.plotting import figure, show
from bokeh.io import output_file

output_file("plot.html")

p = figure(title="Scatter Plot")

p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=15, color="navy", alpha=0.5)

show(p)

Enter fullscreen mode Exit fullscreen mode

Cloud Deployment

Streamlit Community Cloud

  1. Push your app code and requirements.txt to GitHub.
  2. Connect your GitHub account to https://streamlit.io/cloud.
  3. Select the repository and main script (e.g., app.py).
  4. Deploy the app with one click and get a public URL.

Dash on Google Cloud Run (or similar services)

  1. Containerize your Dash app with Docker.
  2. Push the Docker image to Google Container Registry.
  3. Deploy the container using Google Cloud Run to access a public URL.

Bokeh on Posit Connect or Google Cloud Run

  1. Prepare the app for execution with bokeh serve.
  2. Deploy the app on Posit Connect or as a Docker container in Google Cloud Run.
  3. Access your interactive visualizations via a public URL.

Quick Comparison

Final Thoughts

These tools democratize the creation of interactive dashboards and reports, allowing Python developers and data scientists to share insights beyond static graphics. Cloud deployment eases collaboration and remote access, a crucial step to bring projects from local environments to production.

Teams are encouraged to experiment with these tools and share use cases, benefits, and challenges according to their needs.

Top comments (0)