import streamlit as st
"This is a good message!")
st.success(
"This is a not so good, but not catastrophic, message...")
st.warning(
"This is a bad message!")
st.error(
"This is just something we wanted to notify you about.") st.info(
5 Info, Success, Warning and Error Boxes
Streamlit provides several options for displaying text with a background colour to help draw attention to it.
Note
The code won’t be displayed when writing your own app - it’s just shown here so you can easily see which bits of code creates which output.
5.1 Icons
All of the above can also use optional icons.
These icons can either be emojis or icons from Google’s material-ui library.
To do this, you can just pass the icon to the icon argument.
import streamlit as st
"This is a good message!", icon="🚨")
st.success(
"This is a not so good, but not catastrophic, message...", icon=":material/bolt:")
st.warning(
"This is a bad message!", icon="🔥")
st.error(
"This is just something we wanted to notify you about.", icon=":material/thumb_up:") st.info(
5.2 Using conditional logic with error messages
Often you will want to display a different message depending on a user’s input or something similar.
Here’s an example where the user’s input is checked to see if it can be divided exactly by 5. If it cannot, an error message is displayed. If it can be, a success message is displayed.
import streamlit as st
= st.number_input("Please enter a number that can be divided by 5 without leaving a remainder.")
users_number
if users_number % 5 == 0:
"Great!")
st.success(
else:
"That's not a number that can be divided exactly by 5! Try again.") st.error(