Layouts and Containers
Complex layouts
Streamlit 提供了多种选项来控制屏幕上不同元素的布局方式。

列
插入布局为并排列的容器。
col1, col2 = st.columns(2)
col1.write("this is column 1")
col2.write("this is column 2")

容器
插入一个多元素容器。
c = st.container()
st.write("This will show last")
c.write("This will show first")
c.write("This will show second")

模态对话框
插入一个可以独立于脚本其余部分重新运行的模态对话框。
@st.dialog("Sign up")
def email_form():
name = st.text_input("Name")
email = st.text_input("Email")

空
插入一个单元素容器。
c = st.empty()
st.write("This will show last")
c.write("This will be replaced")
c.write("This will show first")

扩展器
插入一个可以展开/折叠的多元素容器。
with st.expander("Open to see more"):
st.write("This is more content")
弹出框
插入一个可以打开/关闭的多元素弹出容器。
with st.popover("Settings"):
st.checkbox("Show completed")

侧边栏
在侧边栏中显示项目。
st.sidebar.write("This lives in the sidebar")
st.sidebar.button("Click me!")

标签页
插入分隔成标签的容器。
tab1, tab2 = st.tabs(["Tab 1", "Tab2"])
tab1.write("this is tab 1")
tab2.write("this is tab 2")
第三方组件
这些是由我们可爱的社区创建的精选组件。更多示例和灵感,请查看我们的 组件库 和 Streamlit 扩展!
还有问题吗?
我们的 论坛 充满了有用的信息和Streamlit专家。