Search code examples
streamlit

Is there a way to change the placeholder text of a spinner in streamlit?


I would like to change the placeholder text displayed when calling a function:

enter image description here

I tried using

with st.spinner(text="Fetching measures"):
    measures = fetch_measures(userid, start_ts, end_ts)

but it just adds a new warning above with “Fetching measures”. Is there a way to just change the text “Running function_name(…)”?


Solution

  • There is a way as found on the Streamlit's forum:

    @st.cache(show_spinner=False)
    def fetch_measures():
        # do stuff
        time.sleep(10)
    
    
    def main():
        with st.spinner(text="Fetching measures"):
            measures = fetch_measures()
    
    if __name__ == "__main__":
        main()
    

    Just add show_spinner=False inside the st.cache() decorator to remove the warning. Then, add your own warning with with st.spinner(text="Fetching measures").