I have a following class that renders some content to the page. All the content I write to the page is held inside an st.empty container within the class. I want to create a button that will a) delete the old content and b) regenerate new content. When I try to achieve this with the following code where the button callback is called to clear the value, it doesnt empty the value but it does generate the new topics:
In my mind, both these code snippets should be equivalent no? (FYI: the empty method call is something I implemented to remove all attached streamlit.components from my container class)
I don’t have your TopicGeneration function to test this out myself, but there is a bit of a bug with st.empty where the backend seems to move ahead faster than the frontend can keep up. If you add time.sleep(.2) immediately after calling the .empty() method, does that change the behavior in the first snippet?
Nope, the old content is still hanging around. Went as far as setting the sleep to 1.0, no difference. Which in my mind doesn’t feel like some racy bug where the empty fails to update the state before the re-render loop, think something is just fundamentally not working with the callbacks? In general, albeit in my very extensive streamlit usage of grand 2 days, I’ve found that when Streamlit state modification within the main scope works as expected but when state mod move into function scopes ie. into functions, things become a little fcky, as per described here as well: Buttons Within a Class Don't Trigger When a Key is Added
Could you post a complete, executable example please? Any simplification to demonstrate just the part that isn’t working as expected would be helpful. I’m trying to stitch together what you’ve posted here and on the new thread, but it’s still incomplete so I don’t have anything to execute yet.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.