【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,
)
相关推荐
<花开花落>20 天前
AI 辅助生成 Mermaid 流程图
ai·流程图·mermaid·tool
@Mr_LiuYang1 个月前
Mermaid 绘图--以企业权限视图为例
数据结构·mermaid·结构图·层次权限·权限关系图
木鱼show2 个月前
Streamlit 项目知识点总结
python·streamlit
SugarPPig2 个月前
Mermaid 文件支持的图表
mermaid
qq_368019662 个月前
Python结合ollama和stramlit开发聊天机器人
开发语言·python·机器人·streamlit·ollama
奔跑吧邓邓子3 个月前
DeepSeek+Mermaid:轻松实现可视化图表自动化生成(附实战演练)
mermaid·可视化图表·自动化生成·deepseek
码上飞扬3 个月前
Streamlit从入门到精通:构建数据应用的利器
streamlit
大霸王龙3 个月前
基于 Streamlit 的 PDF 编辑器
python·pdf·编辑器·streamlit
丁总学Java4 个月前
在 Mermaid 流程图里“驯服”&quot;的魔法指南!!!
流程图·mermaid