Currently running in local mode.
Python Version - 3.10.4
Streamlit Version - 1.37.1
Im trying to build the app for access sharing, for that i want show open request, closed request, my approval.
for that im using st.column, in that i have created 3 buttons. and on clicking on the open request button im trying show a dataframe to select for any rows using st.data_editor. but as soon as i click in any row, the page is getting refreshed.
but if execute the same things with st.column and no button in it. the scenario is working as expected.
found the reference code - How to select single or multiple rows in st.dataframe and return the selected data? - Using Streamlit - Streamlit
any help here would be appreciated.
import streamlit as st
import pandas as pd
st.markdown("<h1 style='text-align: center; '>History</h1>" ,unsafe_allow_html=True)
tab1, tab2, tab3 = st.columns([1, 1, 1])
with tab1:
my_open_requests = st.button("MY OPEN REQUESTS")
with tab2:
my_closed_requests = st.button("MY CLOSED REQUESTS")
with tab3:
my_approvals_requests = st.button("MY APPROVALS")
if my_open_requests:
df = pd.DataFrame(
{
"Animal": ["Lion", "Elephant", "Giraffe", "Monkey", "Zebra"],
"Habitat": ["Savanna", "Forest", "Savanna", "Forest", "Savanna"],
"Lifespan (years)": [15, 60, 25, 20, 25],
"Average weight (kg)": [190, 5000, 800, 10, 350],
}
)
with st.expander("Show dataframe"):
def dataframe_with_selections(df: pd.DataFrame, init_value: bool = False) -> pd.DataFrame:
df_with_selections = df.copy()
df_with_selections.insert(0, "Select", init_value)
# Get dataframe row-selections from user with st.data_editor
edited_df = st.data_editor(
df_with_selections,
hide_index=True,
column_config={"Select": st.column_config.CheckboxColumn(required=True)},
disabled=df.columns,
)
# Filter the dataframe using the temporary column, then drop the column
selected_rows = edited_df[edited_df.Select]
return selected_rows.drop('Select', axis=1)
selection = dataframe_with_selections(df)
st.write("Your selection:")
st.write(selection)
subcol1, subcol2 = st.columns(2)
subcol1.button("Approve")
subcol2.button("Reject")