顯示多選小部件。
多選小部件開始為空。
函數簽名
st.multiselect(label, options, default=None, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False)
參數 | 說明 |
---|---|
label (str) | 一個簡短的標簽,向用戶解釋此選擇小部件的用途。 |
options (Sequence[V], numpy.ndarray, pandas.Series, pandas.DataFrame, or pandas.Index) | 選擇選項的標簽。默認情況下,這將在內部強製轉換為 str 。對於 pandas.DataFrame,第一列被選中。 |
default ([V], V, or None) | 默認值列表。也可以是單個值。 |
format_func (function) | 修改選擇框選項顯示的函數。它接收原始選項作為參數,並應輸出要為該選項顯示的標簽。這對多選的返回值沒有影響。 |
key (str or int) | 一個可選的字符串或整數,用作小部件的唯一鍵。如果省略,將根據其內容為小部件生成一個 key 。相同類型的多個小部件可能不共享相同的鍵。 |
help (str) | 顯示在多選旁邊的可選工具提示。 |
on_change (callable) | 當此多選的值更改時調用的可選回調。 |
args (tuple) | 傳遞給回調的可選參數元組。 |
kwargs (dict) | 一個可選的 kwargs 字典傳遞給回調。 |
disabled (bool) | 一個可選的布爾值,如果設置為 True,則禁用多選小部件。默認值為假。此參數隻能由關鍵字提供。 |
返回 | 說明 |
(list) | 包含所選選項的列表 |
示例
options = st.multiselect(
'What are your favorite colors',
['Green', 'Yellow', 'Red', 'Blue'],
['Yellow', 'Red'])
st.write('You selected:', options)
注意
options
(100+) 的大型列表可能會降低用戶體驗,因為此小部件並非旨在有效處理任意文本搜索。有關更多信息,請參閱 Streamlit 社區論壇上的 thread,有關此問題的更新,請參閱 GitHub issue #1059。
相關用法
- Python Streamlit st.markdown用法及代碼示例
- Python Streamlit st.metric用法及代碼示例
- Python Streamlit st.map用法及代碼示例
- Python Streamlit st.experimental_singleton.clear用法及代碼示例
- Python Streamlit st.bokeh_chart用法及代碼示例
- Python Streamlit st.caption用法及代碼示例
- Python Streamlit st.text_input用法及代碼示例
- Python Streamlit st.area_chart用法及代碼示例
- Python Streamlit st.title用法及代碼示例
- Python Streamlit st.cache用法及代碼示例
- Python Streamlit st.experimental_singleton用法及代碼示例
- Python Streamlit st.empty用法及代碼示例
- Python Streamlit st.error用法及代碼示例
- Python Streamlit st.video用法及代碼示例
- Python Streamlit st.vega_lite_chart用法及代碼示例
- Python Streamlit st.slider用法及代碼示例
- Python Streamlit st.header用法及代碼示例
- Python Streamlit st.container用法及代碼示例
- Python Streamlit st.form_submit_button用法及代碼示例
- Python Streamlit st.form用法及代碼示例
- Python Streamlit st.plotly_chart用法及代碼示例
- Python Streamlit st.bar_chart用法及代碼示例
- Python Streamlit st.code用法及代碼示例
- Python Streamlit st.experimental_memo.clear用法及代碼示例
- Python Streamlit st.warning用法及代碼示例
注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.multiselect。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。