In Python, we use Streamlit to add animations to our apps. These animations involve status and progress messages.
To add the status elements, we’ll first import streamlit
using the following command:
import streamlit as st
It displays a progress bar.
st.progress(value)
value
: This can either be int
(0
-100
) or float
(0.0
-1.0
).It temporarily displays a message while executing a code block.
st.spinner(text="Work in Progress")
text
: This is the message to be displayed.It adds celebratory balloons.
st.balloons()
It displays celebratory snowfall.
st.snow()
Let’s run the following app to display a progress bar that increases over time, a spinner that shows a message after some time, celebratory balloons, and celebratory snowfall.
import streamlit as st import time bar = st.progress(2) for i in range(100): time.sleep(0.04) bar.progress(i + 1) with st.spinner('Wait for it...'): time.sleep(5) st.balloons() st.snow()
streamlit
and time
modules.progress().
It displays an error message.
st.error(body)
body
: This is the error text to be displayed.It displays a warning message.
st.warning(body)
body
: This is the warning text to be displayed.It displays an informational message.
st.info(body)
body
: This is the information text to be displayed.It displays a success message.
st.success(body)
body
: This is the success text to be displayed.It displays an exception.
st.exception(exception)
exception
: This is the exception to be displayed.Let’s run the following app to display the error message, warning box, info box, success box, and an exception on the Streamlit web interface.
import streamlit as st # Error box st.error("An error has occured") # Warning box st.warning("This is a warning") # Info box st.info("We have updated the code") # Success box st.success("Successfully completed!") # Exception output e = RuntimeError('This is an RuntimeError exception') st.exception(e)
streamlit
module.Free Resources