當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Streamlit st.expander用法及代碼示例

插入一個可以展開/折疊的多元素容器。

將一個容器插入到您的應用程序中,該容器可用於容納多個元素,並且可以由用戶展開或折疊。折疊時,所有可見的都是提供的標簽。

要將元素添加到返回的容器中,您可以使用"with" 表示法(首選)或直接在返回的對象上調用方法。請參閱下麵的示例。

警告

目前,您不能將擴展器放在另一個擴展器中。

函數簽名

st.expander(label, expanded=False)
參數說明

label (str)

用作擴展器標頭的字符串。

expanded (bool)

如果為 True,則將擴展器初始化為 "expanded" 狀態。默認為 False(折疊)。

例子

st.line_chart({"data": [1, 5, 2, 6, 2, 1]})

with st.expander("See explanation"):
     st.write("""
         The chart above shows some numbers I picked for you.
         I rolled actual dice for these, so they're *guaranteed* to
         be random.
     """)
     st.image("https://static.streamlit.io/examples/dice.jpg")

或者您可以使用對象表示法並直接在返回的對象中調用方法:

import streamlit as st

st.bar_chart({"data": [1, 5, 2, 6, 2, 1]})

expander = st.expander("See explanation")
expander.write("""
    The chart above shows some numbers I picked for you.
    I rolled actual dice for these, so they're *guaranteed* to
    be random.
""")
expander.image("https://static.streamlit.io/examples/dice.jpg")

相關用法


注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.expander。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。