Best practice for adding a 'Stop' button to `st.chat_input`?

Hi everyone,

I’m working on a chat application where users can trigger a long-running process. I want to give them the ability to stop this process.

I’ve implemented a solution using a separate st.button that toggles a boolean in st.session_state. The running process checks this flag in its loop to know when to terminate.

My question is: Is this the recommended way to handle this? I’ve noticed on the GitHub issues for Streamlit that turning the submit button into a stop button is a requested feature.[1] In the meantime, I’m looking for the most user-friendly and robust way to implement this functionality.

Here are some of my considerations:

  • User Experience: Having a separate “Stop” button is functional, but not as seamless as the submit button transforming into a stop button.
  • State Management: My current method of using st.session_state seems to work, but I’m open to other ideas if they are cleaner.

Does anyone have a more advanced or different approach they could share? Perhaps there’s a clever way to use st.rerun or other features to make this more seamless. I’m aiming for the best possible user experience with the current capabilities of Streamlit.

Thanks in advance for your suggestions

1 Like

I’m having a similar issue where I don’t know how to implement a button that once pressed stops the streaming vLLM generation