Skip to content

Add info on warning: Calling st.experimental_rerun() within a callback is a no-op #422

@evan-wes

Description

@evan-wes

Link to doc page in question (if any):
https://docs.streamlit.io/library/api-reference/control-flow/st.experimental_rerun
Name of the Streamlit feature whose docs need improvement:
st.experimental_rerun
What you think the docs should say:
I have encountered a puzzling warning using st.button callback functions. The warning states:
Calling st.experimental_rerun() within a callback is a no-op.

I can't find any information about this warning except this pull request which appears to implement the warning Make calling st.experimental_rerun() within a callback a no-op which closes this issue: Rerunning the session does not work inside callbacks.

The simple test app I made using the following code triggers this warning (when buttons are pressed in succession) even though st.experimental_rerun is not explicitly run anywhere:

import streamlit as st

def left_callback():
    st.write('Left button was clicked')

def right_callback():
    st.write('Right button was clicked')

left_col, right_col, _ = st.columns([1, 1, 3])

with left_col:
    st.button('LEFT', on_click=left_callback)

with right_col:
    st.button('RIGHT', on_click=right_callback)

It appears that it is an issue with session state and callbacks not properly working together or the app being re-run inside one of the callbacks under the hood.

My suggestion is to add information about possible warnings that st.experimental_rerun() may trigger, including this one I have mentioned. Or add a functionality to suppress the warning. I don't think this is a bug, so I submit this as a documentation improvement in the hopes of getting some answers about why this warning is triggered.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions