Bug (?) preventing iteration over displayed elements with recursive function

Hi @paulwcoles, welcome to the Streamlit community!

This isn’t a bug per se, but a reflection of how the Streamlit evaluation model works. I’ve briefly written about that design decision here:

What is happening is that within your recursive function, you are calling a Streamlit widget (st.button), which is then re-running Streamlit from the top of your script. So instead of getting the behavior you are expecting, you are seeing the code be re-run and the state being lost.

As part of our 2021 roadmap, we’re working on a robust state management functionality, but in the meantime, you can take a look at the following example about maintaining state between runs. If you persist your variable i in state across runs, I think you should get the behavior you are looking for.

Best,
Randy

1 Like