Streamlit Components v2 helpers for Plotly heatmap-like cell events.
Project description
streamlit-plotly-enhance
Enhanced Plotly interaction helpers for Streamlit Components v2.
streamlit-plotly-enhance renders Plotly figures in Streamlit and returns
cell-level interaction events for heatmap-like charts. It is designed for cases
where Streamlit's native st.plotly_chart event support is not enough,
especially heatmap cell click events.
Status
V1 focuses on Plotly heatmap-like charts and click/hover/relayout event payloads. The package is alpha-stage and intentionally conservative: chart types that need highly specialized handling may be refined in later versions.
Installation
From PyPI, after the package is published:
pip install streamlit-plotly-enhance
From GitHub:
pip install git+https://github.com/Jin-Yc/streamlit-plotly-enhance.git
Quick Start
import plotly.graph_objects as go
import streamlit as st
from streamlit_plotly_enhance import plotly_cell_events
st.title("Heatmap cell events")
fig = go.Figure(
data=go.Heatmap(
z=[[1, 2, 3], [4, 5, 6]],
x=["A", "B", "C"],
y=["row-1", "row-2"],
colorscale="Viridis",
name="basic heatmap",
)
)
event = plotly_cell_events(fig, events=("click",), key="heatmap-basic")
st.json(event or {})
Run the example:
streamlit run examples/heatmap_basic.py
Event Payload
Clicking the A / row-2 cell in the quick-start example returns a normalized
payload like:
{
"event": "click",
"plotly_event": "plotly_click",
"trace_type": "heatmap",
"points": [
{
"curve_number": 0,
"point_number": None,
"point_numbers": None,
"row": 1,
"col": 0,
"x": "A",
"y": "row-2",
"z": 4,
"value": 4,
"customdata": None,
"text": None,
"trace_name": "basic heatmap",
"trace_type": "heatmap",
}
],
"relayout": None,
}
API
plotly_cell_events(
fig,
events=("click",),
*,
key=None,
use_container_width=True,
height=None,
config=None,
theme=None,
raw_event=False,
)
Supported V1 events:
clickhoverunhoverrelayout
Primary V1 chart targets:
heatmapimage- common
px.imshowoutputs contourhistogram2dhistogram2dcontour
selected and selecting are not V1 guarantees.
Development
Create a local environment:
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[dev]"
.\.venv\Scripts\python.exe -m pytest
Build the frontend:
cd src/streamlit_plotly_enhance/frontend
npm install
npm run build
The generated src/streamlit_plotly_enhance/frontend/build files are included
in the Python package so users do not need Node.js at runtime.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_plotly_enhance-0.1.0.tar.gz.
File metadata
- Download URL: streamlit_plotly_enhance-0.1.0.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7d67ee45305e6962f1ff617832eb06ad5bb9f247499d9076661008e0075c105
|
|
| MD5 |
25973b1c32ae915c9af63da94324c45b
|
|
| BLAKE2b-256 |
c142ffd7dd527c3f9acdfb1da12045c24ba7682db5ee50913e268c573bb84ccc
|
File details
Details for the file streamlit_plotly_enhance-0.1.0-py3-none-any.whl.
File metadata
- Download URL: streamlit_plotly_enhance-0.1.0-py3-none-any.whl
- Upload date:
- Size: 1.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9a5b3eadac3df572b3913cea1b8f1967c29a99c0927e9eaa8983b042223444b
|
|
| MD5 |
ed31d2529a9a08d65a0ff0cfcc03d8da
|
|
| BLAKE2b-256 |
29b0cc252f274196842c2085289b7c5e2daacac61d33c24394411eeb934e9079
|