由 neevop 十二月 3, 2023
进度条
1.1 st.process
# st.progress(value, text=None)
import streamlit as st
import time
progress_text = "Operation in progress. Please wait."
my_bar = st.progress(0, text=progress_text)
for percent_complete in range(100):
time.sleep(0.01)
my_bar.progress(percent_complete + 1, text=progress_text)
time.sleep(1)
my_bar.empty()
st.button("Rerun")
1.2 st.spinner
# st.spinner(text="In progress...", *, cache=False)
import time
import streamlit as st
with st.spinner('Wait for it...'):
time.sleep(5)
st.success('Done!')
状态
插入状态容器以显示长时间运行的任务的输出
2.1 st.status
# st.status(label, *, expanded=False, state="running")
import time
import streamlit as st
with st.status("Downloading data..."):
st.write("Searching for data...")
time.sleep(2)
st.write("Found URL.")
time.sleep(1)
st.write("Downloading data...")
time.sleep(1)
st.button('Rerun')
2.2 st.toast
显示一条短消息,称为通知“toast”。
# st.toast(body, *, icon=None)
import streamlit as st
import time
if st.button('Three cheers'):
st.toast('Hip!')
time.sleep(.5)
st.toast('Hip!')
time.sleep(.5)
st.toast('Hooray!', icon='🎉')
2.3 st.balloons
画庆祝气球。
import streamlit as st
st.balloons()
2.4 st.snow
import streamlit as st
st.snow()
2.5 st.error
# st.error(body, *, icon=None)
import streamlit as st
st.error('This is an error', icon="🚨")
2.6 st.warning
# st.warning(body, *, icon=None)
import streamlit as st
st.warning('This is a warning', icon="⚠️")
2.7 st.info
# st.info(body, *, icon=None)
import streamlit as st
st.info('This is a purely informational message', icon="ℹ️")
2.8 st.success
# st.success(body, *, icon=None)
import streamlit as st
st.success('This is a success message!', icon="✅")
2.9 st.exception
# st.exception(exception)
import streamlit as st
e = RuntimeError('This is an exception of type RuntimeError')
st.exception(e)