Skip to main content

Interactive Mermaid diagram component for Streamlit with click event handling

Project description

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

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_mermaid_interactive-0.1.12.tar.gz (888.7 kB view details)

Uploaded Source

Built Distribution

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

streamlit_mermaid_interactive-0.1.12-py3-none-any.whl (891.0 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_mermaid_interactive-0.1.12.tar.gz.

File metadata

  • Download URL: streamlit_mermaid_interactive-0.1.12.tar.gz
  • Upload date:
  • Size: 888.7 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for streamlit_mermaid_interactive-0.1.12.tar.gz
Algorithm Hash digest
SHA256 c1367b1c50f2aedc3cb48dd592026817d0d2a0b325f864c9832e0c524b14173b
MD5 7aeafabad514be2a3963dadb682194f0
BLAKE2b-256 87273668571de823b95405c28ab56881b5a427215c85b462035b7111a70ea11a

See more details on using hashes here.

File details

Details for the file streamlit_mermaid_interactive-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: streamlit_mermaid_interactive-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 891.0 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for streamlit_mermaid_interactive-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 60aa439d1acacbfdc128735abf47cd1b839f60117e0c54f08438478fe3c95c94
MD5 e00e616f1763013a17a3e499f60fe46c
BLAKE2b-256 ec7fc4294f862bf9865c04ffdf623170c67c2096bea4efc8518132d3e7cb639b

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