【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,
)
相关推荐
secondyoung7 天前
Pandoc转换Word文档:使用Lua过滤器统一调整Pandoc文档中的图片和表格格式
经验分享·junit·word·lua·markdown·pandoc·mermaid
哥本哈士奇11 天前
Streamlit + LangChain 1.0 简单实现智能问答前后端
langchain·streamlit
草明12 天前
Mermaid 画图
画图·mermaid
凯子坚持 c15 天前
智能开发环境下的 Diagram-as-Code 实践:MCP Mermaid 技术链路拆解
mermaid
Adair_z23 天前
基于 LattePanda Sigma + Claude + Mermaid + Cpolar 打造全栈式家庭教育私有云
claude·cpolar·mermaid·mvel·猜数字大小·艾伦·凯·alan kay
未来之窗软件服务1 个月前
操作系统应用(三十六)golang语言ER实体图开发—东方仙盟筑基期
后端·golang·mermaid·仙盟创梦ide·东方仙盟·操作系统应用
PieroPc2 个月前
一个基于Python Streamlit sqlite3 的销售单管理系统,提供商品管理、客户管理、销售单管理及打印,和应收对账单等功能
python·oracle·sqlite·streamlit
PieroPc2 个月前
用python streamlit sqlite3 写一个聊天室
python·streamlit·聊天室
PieroPc2 个月前
用Python Streamlit Sqlite3 写一个简单商品管理系统
数据库·python·sqlite·streamlit
花酒锄作田3 个月前
用FastAPI和Streamlit实现一个ChatBot
llm·fastapi·streamlit