Strange behaviour with balloons and @st.fragment

Ok, so here is a weird one. I detected this behaviour in my app and was able to recreate this test case. Run the code below.

  1. Click on the balloons button → Balloons will fly
  2. Change the value of the selectbox → Balloons fly again.

Once the balloons fly, they always fly.
This behaviour does not happen with st.toast.
This behaviour is caused by the st.fragment decorator on the frag() function.
Remove it and behaviour is as expected

Question: Is this a bug?

import streamlit as st

@st.fragment
def frag() -> None:
    st.selectbox("Please choose", options=["red", "yellow", "green"])


def balloons() -> None:
    st.balloons()


def toast() -> None:
    st.toast("Toast")


frag()

if st.button("Balloons"):
    balloons()
    # toast()

Tested with streamlit 1.41, 1.43 and 1.44

can someone confirm this behaviour in his environment? Just want to rule out its me.

I can reproduce the bug with streamlit 1.42.2. It happens with checkboxs too, and I guess with any widget that triggers a rerun.

import streamlit as st

@st.fragment
def frag() -> None:
    st.checkbox("Check")


frag()
if st.button("Balloons"):
    st.balloons()
1 Like

Actually when you replace st.balloons with st.toast it does not happen.

Yeah, I can confirm that too.

1 Like