forked from blackary/st_pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_st_page.py
65 lines (42 loc) · 1.92 KB
/
demo_st_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pathlib import Path
import streamlit as st
with st.echo("below"):
from st_pages import Page, Section, add_page_title, show_pages
"## Declaring the pages in your app:"
show_pages(
[
Page("demo_st_page.py", "主页", "🏠"),
# Can use :<icon-name>: or the actual icon
Page("pages/page_1.py", "第一页", ":books:"),
# Since this is a Section, all the pages underneath it will be indented
# The section itself will look like a normal page, but it won't be clickable
Section(name="Cool apps", icon=":pig:"),
# The pages appear in the order you pass them
Page("pages/page_4.py", "Page 四", "📖"),
Page("pages/page_2.py", "Page 二", "✏️"),
Section(name="Other apps", icon=":horse:"),
# Will use the default icon and name based on the filename if you don't pass them
Page("pages/page_3.py"),
# You can also pass in_section=False to a page to make it un-indented
Page("pages/page_5.py", "Page 五", "🧰", in_section=False),
]
)
add_page_title() # Optional method to add title and icon to current page
# Also calls add_indentation() by default, which indents pages within a section
TOML_CONFIG = ".streamlit/pages_sections.toml"
if Path(TOML_CONFIG).exists():
"## Alternative approach, using a config file"
"Contents of `.streamlit/pages_sections.toml`"
st.code(Path(TOML_CONFIG).read_text(), language="toml")
"Streamlit script:"
with st.echo("below"):
from st_pages import show_pages_from_config
show_pages_from_config(TOML_CONFIG)
"See more at https://github.com/blackary/st_pages"
with st.expander("Show documentation"):
from st_pages import add_indentation
st.help(show_pages)
st.help(Page)
st.help(add_page_title)
st.help(Section)
st.help(add_indentation)