I have simplified my code into the following:
x = st.slider("Slider",min_value=1, max_value=10)
for i in range(x):
with st.expander("Test"):
st.write(i)
The problem for me is that say the slider is at 2, resulting in two expander and I click the first expander open. If I then make the slider 4, I will have 4 expanders but the first one is still open. I want all the expanders to collapse once the slider/input changes. I have tried buttons with session state but no luck.