import streamlit as st x = st.slider('年龄', min_value=0,max_value=100, value=25, step=1, key="age") st.write("age is :",x) # 当设置了key后可以使用st.session_state.age在其他位置访问该值 st.write("age is :",st.session_state.age)
选择范围
1 2 3 4
add_slider = st.slider( 'Select a range of values', 0.0, 100.0, (25.0, 75.0) )
下拉选择框
1 2 3 4 5 6 7 8 9 10
import streamlit as st import pandas as pd df = pd.DataFrame({ 'first column': [25, 26, 27, 28], })
option = st.selectbox( '你的年龄是?', df['first column']) st.write("age is :",option)
折线图
1 2 3 4 5 6 7 8 9
import streamlit as st import pandas as pd data = { "接口A速度": [100,150,200,250], "接口B速度": [200, 100, 200, 100], "接口C速度": [100, 90, 120, 100] } chart_data = pd.DataFrame(data) st.line_chart(chart_data)
静态表格
1 2 3 4 5 6 7 8 9
import streamlit as st import pandas as pd data = { "接口A速度": [100,150,200,250], "接口B速度": [200, 100, 200, 100], "接口C速度": [100, 90, 120, 100] } pd_data = pd.DataFrame(data) st.table(pd_data)
进度条
1 2 3 4 5 6 7 8 9 10
import streamlit as st import time
latest_iteration = st.empty() bar = st.progress(0)
for i inrange(100): latest_iteration.text(f'Iteration {i+1}') bar.progress(i + 1) time.sleep(0.1)
if st.button("Home"): st.switch_page("your_app.py") if st.button("Page 1"): st.switch_page("pages/page_1.py") if st.button("Page 2"): st.switch_page("pages/page_2.py")