配置页面的默认设置。

注意

这必须是应用程序页面上使用的第一个Streamlit命令,并且每页只能设置一次。

函数签名[source]

st.set_page_config(page_title=None, page_icon=None, layout="centered", initial_sidebar_state="auto", menu_items=None)

参数

page_title (str or None)

页面标题,显示在浏览器标签中。如果为None,则默认为脚本的文件名("app.py"将显示为"app • Streamlit")。

page_icon (Anything supported by st.image (except list), str, or None)

The page favicon. If page_icon is None (default), the favicon will be a monochrome Streamlit logo.

In addition to the types supported by st.image (except list), the following strings are valid:

  • A single-character emoji. For example, you can set page_icon="🦈".

  • An emoji short code. For example, you can set page_icon=":shark:". For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.

  • The string literal, "random". You can set page_icon="random" to set a random emoji from the supported list above. Emoji icons are courtesy of Twemoji and loaded from MaxCDN.

  • An icon from the Material Symbols library (rounded style) in the format ":material/icon_name:" where "icon_name" is the name of the icon in snake case.

    For example, icon=":material/thumb_up:" will display the Thumb Up icon. Find additional icons in the Material Symbols font library.

Note

Colors are not supported for Material icons. When you use a Material icon for favicon, it will be black, regardless of browser theme.

layout ("centered" 或 "wide")

页面内容应如何布局。默认为 "centered", 将元素限制在一个固定宽度的居中列中; "wide" 使用整个屏幕。

initial_sidebar_state ("auto", "expanded", 或 "collapsed")

侧边栏应如何开始。默认为 "auto", 在小设备上隐藏侧边栏,否则显示。 "expanded" 初始显示侧边栏;"collapsed" 隐藏它。 在大多数情况下,您应该只使用 "auto",否则应用程序在嵌入并在移动设备上查看时会显得不好。

menu_items (dict)

配置出现在此应用程序右上角的菜单。 此字典中的键表示您要配置的菜单项:

  • "Get help": str or None
    此菜单项应指向的URL。 如果为None,则隐藏此菜单项。
  • "Report a Bug": str or None
    此菜单项应指向的URL。 如果为None,则隐藏此菜单项。
  • "About": str or None
    在“关于”对话框中显示的markdown字符串。 如果为None,则仅显示Streamlit的默认“关于”文本。

URL也可以指向电子邮件地址,例如 mailto:john@example.com

示例

import streamlit as st

st.set_page_config(
    page_title="Ex-stream-ly Cool App",
    page_icon="🧊",
    layout="wide",
    initial_sidebar_state="expanded",
    menu_items={
        'Get Help': 'https://www.extremelycoolapp.com/help',
        'Report a bug': "https://www.extremelycoolapp.com/bug",
        'About': "# This is a header. This is an *extremely* cool app!"
    }
)
forum

还有问题吗?

我们的 论坛 充满了有用的信息和Streamlit专家。