Streamlit Mermaid Interactive
A Streamlit component for rendering interactive Mermaid diagrams with click event handling.
Installation
with uv:
uv add streamlit-mermaid-interactive
with pip:
pip install streamlit-mermaid-interactive
Demo
https://mermaid-component.streamlit.app/
Supported Diagram Types
This component currently supports 5 diagram types with full interactivity:
✅ Fully Working
- Flowchart - Click on nodes
- Sequence Diagram - Click on actors/participants
- Entity Relationship Diagram (ERD) - Click on entity boxes
- State Diagram - Click on state boxes
- Class Diagram - Click on class boxes
⚠️ Rendered but Not Interactive
The following diagram types are rendered correctly but clicks do not yet work:
- Pie Chart - Legend items not yet clickable
- Gantt Chart - No identifiable parent containers for tasks
- Git Graph - Commits without IDs have no clickable targets
- User Journey - Task text elements lack identifiable parents
- Timeline - Text elements have no IDs or clickable parents
Usage
import streamlit as st
from streamlit_mermaid_interactive import mermaid
# Example: Flowchart
flowchart_code = """
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[OK]
B -->|No| D[End]
"""
result = mermaid(flowchart_code, theme="neutral", key="flowchart")
if result.get("entity_clicked"):
st.info(f"Clicked: {result['entity_clicked']}")
Supported Themes
"neutral"(default)"dark""forest""base"
Known Limitations
Technical Challenges
The unsupported diagram types have specific issues with Mermaid 11's SVG rendering:
- Pie Charts: Legend items not structured for easy click detection
- Gantt Charts: Task rectangles exist but have no parent containers with IDs
- Git Graphs: Commits created with bare
commitcommand have no commit IDs to extract - User Journey/Timeline: Text elements for tasks/events have no identifiable parent elements with IDs
Why Not More Diagrams?
Mermaid uses different SVG structures for different diagram types. Some structures make it straightforward to identify clickable elements (like ERD entity boxes or State diagram states), while others require complex DOM traversal or text-based parsing that is error-prone.
Development
Building the Frontend
The component uses Vite to bundle the frontend JavaScript with Mermaid 11:
# Install dependencies (first time only)
npm install
# Build the frontend
npm run build
After editing src/streamlit_mermaid_interactive/frontend/component.js, run npm run build to rebuild main.js.
Running Tests
# Run tests
uv run pytest
Manual Testing
Run the demo app:
streamlit run streamlit_app.py
To add support for more diagram types, you would need to:
- Inspect the SVG structure for that diagram type
- Find a reliable selector or ID pattern for clickable elements
- Update the click detection logic in
src/streamlit_mermaid_interactive/frontend/component.js - Rebuild the frontend with
npm run build - Test thoroughly with various diagram configurations
Example App
See streamlit_app.py for examples of all diagram types (both working and non-working).
License
MIT
Release files for streamlit-mermaid-interactive 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| streamlit_mermaid_interactive-0.1.12.tar.gz | 888.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_mermaid_interactive-0.1.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.8 MB
Release files / streamlit_mermaid_interactive-0.1.12.tar.gz
| Download URL | streamlit_mermaid_interactive-0.1.12.tar.gz |
|---|---|
| Size | 888.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1367b1c50f2aedc3cb48dd592026817d0d2a0b325f864c9832e0c524b14173b
|
|
BLAKE2b-256 checksum How to use checksums |
87273668571de823b95405c28ab56881b5a427215c85b462035b7111a70ea11a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / streamlit_mermaid_interactive-0.1.12-py3-none-any.whl
| Download URL | streamlit_mermaid_interactive-0.1.12-py3-none-any.whl |
|---|---|
| Size | 891.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60aa439d1acacbfdc128735abf47cd1b839f60117e0c54f08438478fe3c95c94
|
|
BLAKE2b-256 checksum How to use checksums |
ec7fc4294f862bf9865c04ffdf623170c67c2096bea4efc8518132d3e7cb639b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|