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)