Switch page with switch_page(<page_name>) in callback of st.button

The goal is to click on a button that will activate a callback function. This function deals with data processing and utilizes the switch_page function from streamlit-extras to switch pages. However, a warning message appears stating that st.experimental_rerun() is a no-op in the callback. I believe this is because the implementation of switch_page employs the st.experimental_rerun() function.

The callback function is crucial in my scenario since I employ a loop to generate the layout based on a list of data.

I’m wondering for this kind of use case, is there a solution or workaround?

Code snippet:

from streamlit_extras.switch_page_button import switch_page
num_data = len(data) # num_data=50
for i in range(num_data):
    st.write(f"topic: {data[i]['title']}")
                   kwargs={"payload": data[i]["payload"], "value": data[i]["value"]})

def callback_func(payload, value):
    # data processing

Hi @timho102003

Can you try defining the callback function before using it in the for loop.

You can do this by moving the following to be prior to the for loop:

That’s indeed the case. You can hide the warning by setting the configuration option client.showErrorDetails.