streamlit控件和控制2
streamlit控件和控制2
button: #按钮
download_button: #文件下载
file_uploader: #文件上传
checkbox: #复选框
toggle: #切换框
radio: #单选按钮
selectbox: #下拉单选框
multiselect: #下拉多选框
slider: #滑动条
select_slider: #选择条
text_input: #文本输入框
text_area: #文本输入区域
number_input: #数字输入框,支持加减按钮
date_input: #日期选择框
time_input: #时间选择框
color_picker: #颜色选择器
st.radio
import streamlit as st
genre = st.radio(
"What's your favorite movie genre",
[":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"],
index=None,
)
st.write("You selected:", genre)
import streamlit as st
# Store the initial value of widgets in session state
if "visibility" not in st.session_state:
st.session_state.visibility = "hidden"
st.session_state.disabled = False
st.session_state.horizontal = False
col1, col2 = st.columns(2)
with col1:
st.checkbox("Disable radio widget", key="disabled") # 是否显示
st.checkbox("Orient radio options horizontally", key="horizontal") # 选择是否水平
with col2:
st.radio(
"Set label visibility 👇",
["visible", "hidden", "collapsed"],
key="visible",
label_visibility="visible", # 标签的可见性,visible,hidden,collapsed
disabled=st.session_state.disabled, # 是否禁止可选
horizontal=st.session_state.horizontal, # 是否水平垂直
)
st.selectbox
st.selectbox(label, options, index=0, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, placeholder="Choose an option", disabled=False, label_visibility="visible")
import streamlit as st
option = st.selectbox(
"How would you like to be contacted?",
("Email", "Home phone", "Mobile phone"),
index=None, # 第一次加载的默认值
placeholder="Select contact method...",
)
st.write('You selected:', option)
st.multiselect
st.multiselect(label, options, default=None, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, max_selections=None, placeholder="Choose an option", disabled=False, label_visibility="visible")
import streamlit as st
options = st.multiselect(
'What are your favorite colors',
['Green', 'Yellow', 'Red', 'Blue'],
default=['Yellow', 'Red']) # 多选的默认值
st.write('You selected:', options)
st.select_slider
import streamlit as st
start_color, end_color = st.select_slider(
'Select a range of color wavelength',
options=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'],
value=('red', 'blue'))
st.write('You selected wavelengths between', start_color, 'and', end_color)
st.slider
st.slider(label, min_value=None, max_value=None, value=None, step=None, format=None, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible")
# label 说明
# min_value 最小值
# max_value 最大值
# value 当前值 可以是元组
# step 步长
import streamlit as st
values = st.slider(
'Select a range of values',
0.0, 100.0, (25.0, 75.0))
st.write('Values:', values)
st.progress
import time
import streamlit as st
progress_bar = st.progress(0)
status_text = st.empty()
for i in range(1, 101):
status_text.text("完成%i%%" % i)
progress_bar.progress(i)
time.sleep(0.1)
参考资料
https://docs.streamlit.io/library/get-started 官方文档
https://docs.streamlit.io/library/api-reference/widgets/st.selectbox