Maintaining state

I have a use case where I want to show a user a piece of text or an image, then they will click one or more checkboxes/buttons that indicate the presence of themes or objects in the text/image. When they are done they will click a button to move on to the next piece of text or image and start the process over.

To do this, it seems like the identifier of the text/image would need to be passed back and forth and sometimes altered by the streamlit app (when the user clocks the “next” button) but the id would not explicitly be specified the user. Is there an existing mechanism for doing this?

It seems like a hidden form element would be useful for handling this.

1 Like

Hey @mschmill,

That’s not something that Streamlit has good support for currently – but it’s a common feature request and something we’re absolutely interested in supporting in the API! We have a GitHub issue for it open here.

In the meantime, the SessionState example code referenced in the above issue provides a good workaround for this pattern.

3 Likes

Thanks, that looks like a workable solution!

1 Like