Skip to content

Inconsistent on_change callback timing for st_folium compared to native Streamlit widgets #258

@yun881201

Description

@yun881201

I’ve noticed that st_folium’s on_change callback fires at a different point in the execution flow than native Streamlit widgets. My understanding of Streamlit widget callbacks is that they follow this order:

The widget’s value in st.session_state is updated

Its on_change callback (if any) is executed

The page reruns, with the widget function returning the new value

By contrast, it appears that st_folium only executes its on_change callback when the code reaches the st_folium(...) line during the rerun, rather than immediately after updating session_state. This discrepancy breaks assumptions that “callback runs as a prefix to the script rerunning” and complicates synchronizing map state with custom session-state management.

Can you please clarify:

Is the st_folium callback intentionally designed to fire only at its invocation line, rather than immediately upon state change?

If so, is there a recommended pattern for guaranteeing that on_change callbacks see and update the very latest map state, in the same way native widgets do?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions