Skip to main content

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

  1. Flowchart - Click on nodes
  2. Sequence Diagram - Click on actors/participants
  3. Entity Relationship Diagram (ERD) - Click on entity boxes
  4. State Diagram - Click on state boxes
  5. Class Diagram - Click on class boxes

⚠️ Rendered but Not Interactive

The following diagram types are rendered correctly but clicks do not yet work:

  1. Pie Chart - Legend items not yet clickable
  2. Gantt Chart - No identifiable parent containers for tasks
  3. Git Graph - Commits without IDs have no clickable targets
  4. User Journey - Task text elements lack identifiable parents
  5. 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 commit command 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:

  1. Inspect the SVG structure for that diagram type
  2. Find a reliable selector or ID pattern for clickable elements
  3. Update the click detection logic in src/streamlit_mermaid_interactive/frontend/component.js
  4. Rebuild the frontend with npm run build
  5. 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)

Source distribution for streamlit-mermaid-interactive 0.1.12
File Size Uploaded
streamlit_mermaid_interactive-0.1.12.tar.gz 888.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-mermaid-interactive 0.1.12
File Interpreter ABI Platform
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}

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files

0.1.11

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page