[Python] Spinner gets pushed up and doesn't stay below chat messages

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a function that executes a plan and I want to have a spinner showing that the plan gets executed so I just did:

    with st.spinner("executing plan..."):
    execute_plan()


    and this works fine, but my big issue is that inside execute_plan() I generate streamlit messages that show the results of each step execution of the plan with:

    with st.chat_message(role, avatar=LOGO_MONO_FILEPATH):
    st.markdown(message)


    My problem is that the loading spinner will be shown above those messages and at some point will move out of the display window which is annoying. I need the spinner to stay below the messages just above the chat input

    Any ideas how I can achieve this behavior?

    Code to reproduce behavior:

    import time
    import streamlit as st

    def dummy_messages():
    for i in range(1,5):
    with st.chat_message("user"):
    st.markdown("hello")
    time.sleep(2)

    with st.spinner("loading"):
    dummy_messages()


    [​IMG]

    Continue reading...

Compartilhe esta Página