【streamlit streamlit中 显示 mermaid 流程图有两种方式】

streamlit中显示mermaid 流程图有两种方式

mermaind示例

python 复制代码
code = """
flowchart LR
    markdown["`This **is** _Markdown_`"]
    newLines["`Line1
    Line 2
    Line 3`"]
    markdown --> newLines

    markdown["`This **is** _Markdown_`"]
    newLines["`Line1
    Line 2
    Line 3`"]
    markdown --> newLines


    markdown["`This **is** _Markdown_`"]
    newLines["`Line1
    Line 2
    Line 3`"]
    markdown --> newLines
"""

方案一

python 复制代码
# pip install streamlit-mermaid
import streamlit_mermaid as stmd
stmd.st_mermaid(
    code,
    show_controls=False,
)

方案二

python 复制代码
import streamlit.components.v1 as components

components.html(
    f"""
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <div class="mermaid-container" style="overflow-y: auto; max-height: 750px;">
        <div class="mermaid">
        {code}
        </div>
    </div>
    <script>
        mermaid.initialize({{
            startOnLoad: true,
            fontFamily: 'monospace, sans-serif',
            flowchart: {{
                htmlLabels: true,
                useMaxWidth: true,
            }},
            securityLevel: 'loose',
        }});
        mermaid.parseError = function(err, hash) {{
            console.error('Mermaid error:', err);
        }};
    </script>
    """,
    # height=750,
)
相关推荐
weixin_462446234 天前
使用 Python 测试 Mermaid 与 Graphviz 图表生成(支持中文)
python·mermaid·graphviz
红桃Jk16 天前
关于开发文档向 Markdown(Docs-as-Code)转型的可行性研究报告
ai·mermaid
爬点儿啥18 天前
[Ai Agent] 13 用 Streamlit 为 Agents SDK 打造可视化“驾驶舱”
人工智能·ai·状态模式·agent·streamlit·智能体
secondyoung1 个月前
Pandoc转换Word文档:使用Lua过滤器统一调整Pandoc文档中的图片和表格格式
经验分享·junit·word·lua·markdown·pandoc·mermaid
哥本哈士奇1 个月前
Streamlit + LangChain 1.0 简单实现智能问答前后端
langchain·streamlit
草明1 个月前
Mermaid 画图
画图·mermaid
凯子坚持 c1 个月前
智能开发环境下的 Diagram-as-Code 实践:MCP Mermaid 技术链路拆解
mermaid
Adair_z1 个月前
基于 LattePanda Sigma + Claude + Mermaid + Cpolar 打造全栈式家庭教育私有云
claude·cpolar·mermaid·mvel·猜数字大小·艾伦·凯·alan kay
未来之窗软件服务2 个月前
操作系统应用(三十六)golang语言ER实体图开发—东方仙盟筑基期
后端·golang·mermaid·仙盟创梦ide·东方仙盟·操作系统应用
PieroPc2 个月前
一个基于Python Streamlit sqlite3 的销售单管理系统,提供商品管理、客户管理、销售单管理及打印,和应收对账单等功能
python·oracle·sqlite·streamlit