I’m looking to reset the session_state to zero, whenever a new value got selected in the Ag Grid table/dataframe. Below is the code that I’m currently using, any help would be really great.
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, GridUpdateMode, JsCode
from st_aggrid.grid_options_builder import GridOptionsBuilder
from PIL import Image
# Functions
@st.cache
def data_upload():
df = pd.read_csv("songs_normalize.csv")
return df
#st.header("This is Streamlit Default Dataframe")
df = data_upload()
gd = GridOptionsBuilder.from_dataframe(df)
gd.configure_pagination(enabled=True)
# gd.configure_default_column(editable=True,groupable=True)
gd.configure_side_bar()
# sel_mode = st.radio('Selection Type', options = ['single', 'multiple'])
gd.configure_selection(selection_mode='multiple',use_checkbox=True)
gridoptions = gd.build()
with st.sidebar:
grid_table = AgGrid(df,gridOptions=gridoptions,
update_mode= GridUpdateMode.SELECTION_CHANGED,
height = 500,
allow_unsafe_jscode=True,
#enable_enterprise_modules = True,
theme = 'blue')
# st.sidebar(grid_table)
sel_row = grid_table["selected_rows"]
st.sidebar.subheader("Output")
st.sidebar.dataframe(sel_row)
lst_imgs = []
for loc in sel_rows['location']:
lst_imgs.extend(list(df['image name'][df['location'] == loc]))
st.write(lst_imgs)
next_button = st.button('next')
if "current_index" not in st.session_state:
st.session_state.current_index = 0
if next_button:
st.session_state.current_index += 1
st.write(lst_imgs[st.session_state.current_index])
st.image(Image.open(lst_imgs[st.session_state.current_index]))