参考:
https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py
https://docs.streamlit.io/en/stable/api.html?highlight=FORM#streamlit.form
https://docs.streamlit.io/en/stable/session_state_api.html#use-callbacks-to-update-session-state
import streamlit as st
a = st.sidebar.radio('R:',[1,2])
st.button('Hit me')
st.checkbox('Check me out')
st.radio('Radio', [1,2,3])
st.selectbox('Select', [1,2,3])
st.multiselect('Multiselect', [1,2,3])
st.slider('Slide me', min_value=0, max_value=10)
st.select_slider('Slide to select', options=[1,'2'])
st.text_input('Enter some text')
st.number_input('Enter a number')
st.text_area('Area for textual entry')
st.date_input('Date input')
st.time_input('Time entry')
st.file_uploader('File uploader')
st.color_picker('Pick a color')
st.text('Fixed width text')
st.markdown('_Markdown_') # see *
st.latex(r''' e^{i\pi} + 1 = 0 ''')
st.write('Most objects') # df, err, func, keras!
st.write(['st', 'is <', 3]) # see *
st.title('My title')
st.header('My header')
st.subheader('My sub')
st.code('for i in range(8): foo()')
x = st.slider('Select a value')
st.write(x, 'squared is', x * x)
import time
st.progress(1)
st.progress(100)
st.spinner()
with st.spinner(text='In progress'):
time.sleep(5)
st.success('Done')
st.balloons()
st.error('Error message')
st.warning('Warning message')
st.info('Info message')
st.success('Success message')
#st.exception("error")
for i in range(int(st.number_input('Num:'))):
st.text('Fixed width text')
if st.sidebar.selectbox('I:',['f']) == 'f':
st.text('Fixed width text')
my_slider_val = st.slider('Quinn Mallory', 1, 88)
st.write(my_slider_val)
col1, col2 = st.beta_columns(2)
col1.subheader('Columnisation')
st.beta_expander('Expander')
with st.beta_expander('Expand'):
st.write('Juicy deets')
with st.echo():
st.write('Code will be executed and printed')
#st.image('./img_00001.png')
#st.audio("https://www.youtube.com/watch?v=kgJMaP4msTs")
#st.video("https://www.youtube.com/watch?v=kgJMaP4msTs")
并列和python通信
import streamlit as st
#https://docs.streamlit.io/en/stable/session_state_api.html#session-state-and-widget-state-association
#https://docs.streamlit.io/en/stable/session_state_api.html#use-callbacks-to-update-session-state
#https://docs.streamlit.io/en/stable/api.html?highlight=FORM#streamlit.form
def form_callback():
st.write(st.session_state.my_slider)
st.write(st.session_state.my_checkbox)
with st.form(key='my_form'):
slider_input = st.slider('My slider', 0, 10, 5, key='my_slider')
checkbox_input = st.checkbox('Yes or No', key='my_checkbox')
submit_button = st.form_submit_button(label='Submit', on_click=form_callback)
# python更新前端的值
cccc = 1.0
def form_callback2():
st.session_state.thresh = cccc
with st.form(key='my_form2'):
height_loosen_thresh = st.sidebar.number_input(label='height loosen thresh', #value=3.2,
min_value=1.0, max_value=30.0,
format='%f', key='thresh')
submit_button = st.form_submit_button(label='Submit2', on_click=form_callback2)
col1, col2, col3 = st.beta_columns(3)
with col1:
st.header("A cat")
st.image("https://static.streamlit.io/examples/cat.jpg")
with col2:
st.header("A dog")
st.image("https://static.streamlit.io/examples/dog.jpg")
with col3:
st.header("An owl")
st.image("https://static.streamlit.io/examples/owl.jpg")
acol1, acol2, acol3 = st.sidebar.beta_columns(3)
with acol1:
height_loosen_thresh1 = st.number_input(label='height', #value=3.2,
min_value=1.0, max_value=30.0,
format='%f', key='thresh1')
with acol2:
height_loosen_thresh2 = st.number_input(label='height', #value=3.2,
min_value=1.0, max_value=30.0,
format='%f', key='thresh2')
with acol3:
height_loosen_thresh3 = st.number_input(label='height', #value=3.2,
min_value=1.0, max_value=30.0,
format='%f', key='thresh3')
bcol1, bcol2, bcol3 = st.beta_columns(3)
with bcol1:
height_loosen_thresh4 = st.number_input(label='height', #value=3.2,
min_value=1.0, max_value=30.0,
format='%f', key='thresh4')
with bcol2:
height_loosen_thresh5 = st.number_input(label='height', #value=3.2,
min_value=1.0, max_value=30.0,
format='%f', key='thresh5')
with bcol3:
height_loosen_thresh6 = st.number_input(label='height', #value=3.2,
min_value=1.0, max_value=30.0,
format='%f', key='thresh6')