Clear selections from CheckboxColumn in data_editor

Hi.
I’m trying to create a function that resent the selections made in CheckboxColumn in data_editor.
My code clears the edited_rows dict, but the checkbox still appears in the UI.

Sample code:

df = ...
df_with_selections = df.copy()
df_with_selections.insert(0, "Select", False)

def clear_selection() -> None:
    for row in st.session_state.data_editor["edited_rows"].values():
        row["Select"] = False

edited_df = st.data_editor(
    data=df_with_selections,
    hide_index=True,
    column_config={"Select": st.column_config.CheckboxColumn(required=True)},
    disabled=df.columns,
    key="data_editor",
)

selected_rows = edited_df[edited_df.Select]
if len(selected_rows) > 0:
    st.write("Your selection:")
    st.write(selected_rows.drop(columns=["Select"]))

st.button("Refresh data", on_click=clear_selection)

Hello @Yaron_Taub, welcome to our community! We’re delighted to have you with us! :hugs:

If you’re facing an issue where checkboxes in a CheckboxColumn aren’t updating on the UI even after running your function to clear them, you might consider using st.rerun() at the end of your clear_selection function.

This command forces Streamlit to rerun your entire script, which should then update the UI and hopefully sort your issue.

Please let me know how it works out for you!

Best,
Charly

Hi @Charly_Wargnier !
Thank you so much for your reply, and I apologize for my unfashionably late reply.

I actually tried this way, but I get an error:
Calling st.rerun() within a callback is a no-op.

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