Skip to main content

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:

  • click
  • hover
  • unhover
  • relayout

Primary V1 chart targets:

  • heatmap
  • image
  • common px.imshow outputs
  • contour
  • histogram2d
  • histogram2dcontour

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_plotly_enhance-0.1.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_plotly_enhance-0.1.0-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file streamlit_plotly_enhance-0.1.0.tar.gz.

File metadata

File hashes

Hashes for streamlit_plotly_enhance-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c7d67ee45305e6962f1ff617832eb06ad5bb9f247499d9076661008e0075c105
MD5 25973b1c32ae915c9af63da94324c45b
BLAKE2b-256 c142ffd7dd527c3f9acdfb1da12045c24ba7682db5ee50913e268c573bb84ccc

See more details on using hashes here.

File details

Details for the file streamlit_plotly_enhance-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_plotly_enhance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9a5b3eadac3df572b3913cea1b8f1967c29a99c0927e9eaa8983b042223444b
MD5 ed31d2529a9a08d65a0ff0cfcc03d8da
BLAKE2b-256 29b0cc252f274196842c2085289b7c5e2daacac61d33c24394411eeb934e9079

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page