st.rerun() stops the current Streamlit execution and starts the app again from the top. It is useful after changing data so the interface immediately reflects the update. section 4.5.4
Refreshing after a deletion
After a Delete button removes a task, calling st.rerun() refreshes the displayed task list and removes the deleted item from the interface. section 4.5.4
Use reruns selectively:
- Trigger the rerun only when an interaction actually changes state. section 4.5.7
- Avoid unconditional reruns inside branches that run again with the same state; they can create an infinite loop and make the app stop responding. section 4.5.6
- After saving a haiku successfully, rerunning refreshes the app and closes the dialog because its triggering button is no longer clicked. section 8.5.2
checked = task_col.checkbox(label, task.is_done, key=f"task_{idx}") #1
if checked and not task.is_done: #2
mark_done(task)
st.rerun()
elif not checked and task.is_done: #3
mark_not_done(task)
st.rerun()
This conditional pattern updates checkbox state and reruns only when the stored status differs from the user’s selection. section 4.5.7
