I decided to create myself a function with the possibility of not only removing a Markdown, but also customizing it as a success, warning or error (danger) message:
1- create a file named “customMsg.py” inside your project’s folder;
2- inside the customMsg.py file, put the following code:
import time
import streamlit as st
# How to use:
# ============
# msg = string
# wait = integer - default to 3
# type_ = string - default to warning (success, warning, danger)
def customMsg(msg, wait=3, type_='warning'):
placeholder = st.empty()
styledMsg = f'\
<div class="element-container" style="width: 693px;">\
<div class="alert alert-{type_} stAlert" style="width: 693px;">\
<div class="markdown-text-container">\
<p>{msg}</p></div></div></div>\
'
placeholder.markdown(styledMsg, unsafe_allow_html=True)
time.sleep(wait)
placeholder.empty()
3- inside your Streamlit web app, import the module:
from customMsg import customMsg
4- use it as in the example below:
your message (string), time to sleep before disappear (integer), type of message - ‘warning’, ‘success’ or ‘danger’ (string)
msg = 'This is my message to the user.'
customMsg(msg, 3, 'warning')
Hi @julio, glad to hear you figured out a solution.
In general, you can write over a Markdown section by reusing the same st.empty() placeholder, so you might not need your own markdown function, but it’s also possible I’m not understanding your use case.