Hi there!
I have an idea to implement to streamlit, but I can’t really understand how to do it.
So I have a dataframe which I showed using st.dataframe(). Now there is a button which the user can click, and some rows of the dataframe will be deleted (this is then saved into a new variable). This is implemented by having on_select=“multi-rows” in the original dataframe, and the user can choose the corresponding rows to delete.
Now the problem is, if the user wants to delete some rows from the table, I only want to show the resulting table (or, if possible, to hide the original table in an expander). In other words, I want to “unshow” the original table. Is there a way to do it? Using session_state does not help.
Here is a snippet of the code :
st.dataframe(
df,
key="df",
on_select="rerun",
selection_mode="multi-row",
)
selected_rows = st.session_state["df"].selection["rows"]
if len(selected_rows):
if st.button("Remove rows"):
df_updated = df.drop(selected_rows)
if len(df) != len(df_updated):
st.dataframe(df_updated)
So here, I want to “unshow” the first dataframe. Is there a way to do it?
Thanks in advance
P.S. : Due to some reasons, I do not want to use st.data_editor() to delete the columns. I know that with st.data_editor, we can only show the current table, but this is not what I want.