New Component: streamlit-mermaid-interactive – Interactive Mermaid Diagrams with Click Events
I’ve just released streamlit-mermaid-interactive, a component that lets you render Mermaid diagrams and respond to click events on nodes/entities.
Demo
https://mermaid-component.streamlit.app/
Installation
pip install streamlit-mermaid-interactive
Why this component?
While there are a few Mermaid components out there, I wanted one that would let users click on diagram elements and have that interaction available in Python. This makes it possible to build apps where clicking a node in a flowchart triggers a query, updates another widget, or navigates to more detail.
Basic Usage
import streamlit as st
from streamlit_mermaid_interactive import mermaid
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 Diagram Types
Fully Interactive (click events work):
- Flowcharts
- Sequence Diagrams
- Entity Relationship Diagrams (ERD)
- State Diagrams
- Class Diagrams
Rendered but not yet clickable:
- Pie Chart, Gantt, Git Graph, User Journey, Timeline
(PRs welcome if anyone wants to tackle click detection for those!)
Themes
Supports "neutral" (default), "dark", "forest", and "base".
Let me know if you run into issues or have feature requests!