Streamlit多页应用的实验版本
项目描述
Streamlit-Pages
作者: @blackary
代码: https://github.com/blackary/st_pages
安装
pip install st-pages
查看操作示例
基本示例: https://st-pages.streamlit.app/
带部分的示例: https://st-pages-sections.streamlit.app/
为什么选择st-pages?
之前,st-pages允许在Streamlit应用程序中对页面进行更多自定义和灵活的声明,并且与项目中的Python文件的实际文件名无关。
从1.0.0版本开始,st-pages现在是一个小型的包装器,它提供了一个在toml文件中轻松定义应用程序页面以及在所有页面上添加当前页面标题等的一些实用方法。
欢迎继续使用此软件包的旧版本,但大多数旧用例现在都可以使用原生streamlit轻松完成,因此我建议查看文档以获取更多信息。
如何使用
在toml文件内声明页面
.streamlit/pages.toml
的内容
[[pages]]
path = "page1.py"
name = "Home"
icon = "🏠"
[[pages]]
path = "other_pages/page2.py"
name = "Page 2"
icon = ":books:"
url_path = "my_books" # You can override the default url path for a page
带部分的示例,.stremalit/pages_sections.toml
[[pages]]
path = "page1.py"
name = "Home"
icon = "🏠"
[[pages]]
path = "other_pages/page2.py"
name = "Page 2"
icon = ":books:"
[[pages]]
name = "My section"
icon = "🎈️"
is_section = true
# Pages after an `is_section = true` will be indented
[[pages]]
name = "Another page"
icon = "💪"
Streamlit代码
import streamlit as st
from st_pages import add_page_title, get_nav_from_toml
st.set_page_config(layout="wide")
# If you want to use the no-sections version, this
# defaults to looking in .streamlit/pages.toml, so you can
# just call `get_nav_from_toml()`
nav = get_nav_from_toml(".streamlit/pages_sections.toml")
st.logo("logo.png")
pg = st.navigation(nav)
add_page_title(pg)
pg.run()
隐藏页面
您现在可以向hide_pages
传递一个页面名称列表以隐藏页面。
此页面列表针对每个应用程序查看者都是自定义的,因此您可以使用此方法隐藏一个查看者的页面而不隐藏另一个查看者的页面。您可以在文档中查看隐藏页面的另一个示例 此处
from st_pages import hide_pages
hide_pages(["Another page"])
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
st_pages-1.0.1.tar.gz (21.3 kB 查看哈希值)
构建分发
st_pages-1.0.1-py3-none-any.whl (20.1 kB 查看哈希值)