@st.cache_data(experimental allow widgets = True) is not working with st.code


Suppressing the CachedStFunctionWarning with @st.cache_data(experimental_allow_widgets=True) together with st.code does not work for me.

Code used in this example can be found here.

Steps to reproduce

Code snippet:

@st.cache_data(experimental_allow_widgets=True, show_spinner=False)
def foo(i):
    options = ["foo", "bar", "baz", "qux"]
    r = st.radio("radio", options, index=i)
    return r


CachedStFunctionWarning is not suppressed.

Expected behavior:

CachedStFunctionWarning disappears if @st.cache_data(experimental_allow_widgets=True) was used in code.

Actual behavior:

Debug info

  • Streamlit version: 1.23.1
  • Python version: 3.11.1

Hi @Jana, welcome to the community! :wave: :smile:

I was able to reproduce this behavior and it clearly seems like a bug. It used to work as intended (without the warning) in version 1.20.0, indicating this issue is a regression.

st.code is a static element, not an input widget. So it should technically work even without experimental_allow_widgets=True.

Would you mind submitting a bug report in the Streamlit GitHub repository? Our team will triage your report and work on a fix.

Thank you for helping make Streamlit better!

Happy Streamlit-ing! :balloon:

PS: If it seems like a lot of work, please let me know if you’d like me to submit a bug report on your behalf.

1 Like

Thanks for the quick answer! I submitted the bug here.


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.