-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streamlit balloons not working in callback for function decorated with fragment #9621
Comments
I tried to reproduce the issue here. But it almost seems to work as expected. Only the first interaction with the toggle does not seem to trigger the balloons. Can you share a video on how it looks for you? |
okay, that's strange, because for me it's showing nothing no matter how I switch the toggle. I noticed for your reproduction, the balloon appear even the toggle is switched off. (after you switch it on off the first time) |
I was able to reproduce this issue locally. It seems that there is an issue with the interaction of fragments, balloons, and callbacks. But not sure why it doesn't work. |
I have looked into this and here is a workaround: import streamlit as st
balloons_placeholder = st.empty()
def callback():
call = st.session_state.test_balloons
if call:
print("AAAAAAAAAAA") ## this gets printed
balloons_placeholder.balloons()
else:
balloons_placeholder.empty()
@st.fragment ## if I comment out st.fragment, it works
def test():
button = st.toggle("turn on balloons", on_change=callback, value=True, key="test_balloons")
test() Actually, it does not only affect The workaround here is that we have an The right thing to do here likely would be to run callbacks that were registered within a fragment run in the fragment context and, thereby, let it write into the fragment container. Though I hope the workaround is sufficient for now! |
Checklist
Summary
I wrote a test code to show balloons in the callback of a function with st.fragment decorator, but it's not showing anything. Below is my reproducible test code. In my actual code, the balloons show halfway and keep on rerunning even though the print line before the st.balloon() call is printed only once.
I'm not sure if it's expected behavior if the balloons don't work in the callback of a fragment. In the test code the balloons don't appear while in my actual code the balloons appear nonstop.
Reproducible Code Example
Steps To Reproduce
Expected Behavior
Balloons should work in the callback of functions with st.fragment decorator
Current Behavior
No balloons appear when toggle is turned on for balloons in callback
Is this a regression?
Debug info
Additional Information
No response
The text was updated successfully, but these errors were encountered: