A lightweight Python package that seamlessly integrates Bokeh plots into Streamlit apps, allowing for interactive, customizable, and responsive visualizations with minimal effort.
Please file bug reports and enhancement requests through our main Streamlit repo.
- Effortlessly embed Bokeh figures in Streamlit apps.
- Responsive layout support with
use_container_width. - Customizable themes (
streamlit(which supports both light and dark mode) or Bokeh Themes)
pip install streamlit-bokehEnsure you have Streamlit and Bokeh installed as well:
pip install streamlit bokehHere's how to integrate a simple Bokeh line plot into your Streamlit app:
from bokeh.plotting import figure
from streamlit_bokeh import streamlit_bokeh
# Data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# Create Bokeh figure
YOUR_BOKEH_FIGURE = figure(title="Simple Line Example",
x_axis_label="x",
y_axis_label="y")
YOUR_BOKEH_FIGURE.line(x, y, legend_label="Trend", line_width=2)
# Render in Streamlit
streamlit_bokeh(YOUR_BOKEH_FIGURE, use_container_width=True, theme="streamlit", key="my_unique_key")figure(bokeh.plotting.figure): The Bokeh figure object to display.use_container_width(bool, optional): Whether to override the figure's native width with the width of the parent container. This isTrueby default.theme(str, optional): The theme for the plot. This can be one of the following strings:"streamlit"(default): Matches Streamlit's current theme.- A Bokeh theme name including:
"caliber""light_minimal""dark_minimal""contrast"
key(str, optional but recommended): An optional string to give this element a stable identity. If this isNone(default), this element's identity will be determined based on the values of the other parameters.
streamlit run app.pyWhere app.py contains:
import streamlit as st
from bokeh.plotting import figure
from streamlit_bokeh import streamlit_bokeh
# Sample Data
x = [1, 2, 3, 4, 5]
y = [2, 4, 8, 16, 32]
# Create Plot
p = figure(title="Exponential Growth", x_axis_label="x", y_axis_label="y")
p.line(x, y, legend_label="Growth", line_width=3, color="green")
# Display in Streamlit
streamlit_bokeh(p, use_container_width=True, key="plot1")We designed the versioning scheme for this custom component to mirror the Bokeh version with the exception of the patch number. We reserve that so we can make bug fixes and new (mostly compatible) features.
For example, 3.6.x will mirror a version of Bokeh that's 3.6.y.
Feel free to file issues in our Streamlit Repository.
Contributions are welcome 🚀, however, please inform us before building a feature.
This project is licensed under the Apache 2.0.
Q: Can I embed multiple Bokeh plots on the same page?
- A: Yes! Just make sure each plot has a unique
key.
Q: Does it support Bokeh widgets?
- A: Currently,
streamlit-bokehfocuses on plots. For widget interactivity, consider combining with native Streamlit widgets.
Q: How do I adjust the plot size?
- A: Use
use_container_width=Truefor responsive sizing, or manually setplot_widthandplot_heightin your Bokeh figure.
Happy Streamlit-ing! 🎉