Streamlit多页面应用项目教程
项目目录结构及介绍
st_pages/
├── github/
│ └── workflows/
├── src/
│ └── st_pages/
├── tests/
├── .flake8
├── .gitignore
├── .pre-commit-config.yaml
├── LICENSE
├── README.md
├── logo.png
├── poetry.lock
├── pyproject.toml
└── tox.ini
- github/workflows: 包含GitHub Actions的工作流配置文件。
- src/st_pages: 项目的核心代码目录。
- tests: 测试文件目录。
- .flake8: 代码风格检查配置文件。
- .gitignore: Git忽略文件配置。
- .pre-commit-config.yaml: 预提交钩子配置文件。
- LICENSE: 项目许可证。
- README.md: 项目说明文档。
- logo.png: 项目logo图片。
- poetry.lock: Poetry依赖锁定文件。
- pyproject.toml: 项目配置文件。
- tox.ini: Tox配置文件。
项目启动文件介绍
项目的启动文件通常是src/st_pages
目录下的主文件,例如streamlit_app.py
。这个文件负责初始化应用并加载配置。
import streamlit as st
from st_pages import Page, show_pages, add_page_title
# 添加页面标题
add_page_title()
# 定义页面
show_pages([
Page("streamlit_app.py", "Home", "🏠"),
Page("other_pages/page2.py", "Page 2", ":books:")
])
# 主应用逻辑
st.title("欢迎使用Streamlit多页面应用")
项目配置文件介绍
项目的配置文件通常是pyproject.toml
,它包含了项目的依赖、构建系统和一些自定义配置。
[tool.poetry]
name = "st-pages"
version = "1.0.0"
description = "An experimental version of Streamlit Multi-Page Apps"
authors = ["Your Name <you@example.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.8"
streamlit = "^1.0.0"
[tool.poetry.dev-dependencies]
pytest = "^6.2"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
- [tool.poetry]: 项目的基本信息。
- [tool.poetry.dependencies]: 项目依赖。
- [tool.poetry.dev-dependencies]: 开发依赖。
- [build-system]: 构建系统配置。
以上是基于开源项目st_pages
的教程,包含了项目的目录结构、启动文件和配置文件的介绍。希望对你有所帮助!
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考