docs
Streamlit

Streamlit (opens in a new tab)

工具

  1. Streamlit 组件模版 (opens in a new tab)

组件库

  1. streamlit-elements (opens in a new tab)
  2. streamlit-shadcn-ui (opens in a new tab): 在 streamlit 中使用 shadcn-ui 组件

Pandas

  1. pd.read_csv: 读取 csv 文件

模块

  1. streamlit_autorefresh (opens in a new tab): 基于 js 的定时器,可以通过传参中断当前,重新开始计时。
  • 页面 10 分后给出提示,可以用这个来判断何时开始 10 分倒计时。

    import streamlit as st
    import streamlit.components.v1 as components
     
    import streamlit as st
     
     
    from streamlit_autorefresh import st_autorefresh
     
    if "key" not in st.session_state:
        st.session_state["key"] = 0
     
    key = f"key_{st.session_state.key}"
     
     
    count = st_autorefresh(interval=5000, limit=1000, key=key)
     
    st.write("count", count)
    st.write("key:", key)
     
    if st.button("text"):
        st.session_state["key"] += 1
     
    if st.button("rerun"):
        st.rerun()
     
    if count > 0:
        components.html(
            f"""
            <script>
                alert('您太久没有操作{key}')
            </script>
            """
        )

技巧

  1. 使用 st.connection()来插入 sql
from sqlalchemy import text
with conn.session as session:
    created_at = datetime.now()
    sql = text(
        "INSERT INTO task_group (name, created_at) VALUES (:name, :created_at);"
    )
 
    # 然后执行查询
    session.execute(sql, {"name": name, "created_at": created_at})
    session.commit()
  1. 使用pm2进程守护
pm2 start --interpreter=<conda_installation_path>/envs/<env_name>/bin/python --name=my-streamlit-app --cwd=<path_to_your_script> --interpreter-args="-m streamlit run" demo.py
 

相关

  1. Pandas (opens in a new tab): 一个强大的 Python 数据处理和数据分析库。

有用的模块

  1. Pygwallker (opens in a new tab): 将 pandas 数据转换为可视化交互 UI GitHub starslast commit
  2. streamlit-aggrid (opens in a new tab): streamlit 版本的 Ag-grid。GitHub starslast commit
  3. Streamlit-Authenticator (opens in a new tab): 登录模块 GitHub starslast commit
  4. st-annotated-text (opens in a new tab): 多种颜色文本标注。GitHub starslast commit
  5. streamlit-extras (opens in a new tab): 扩充了好多streamlit组件GitHub starslast commit
  6. st_pages (opens in a new tab): 路由自定义

最佳实践

  1. 构建 llm 形式的对话应用程序 (opens in a new tab)