@Shawn_Pereira
you told about this
- Some widgets (like buttons) cause a streamlit refresh (re-running of code from the top)
- In such a scenario, if you have a variable:
a. initially set to a certain value, and
b. later change the variable value, and
c. press the widget that causes a refresh
your variable will again start with its initial defined value
If you want a variable to persist its value across refreshes, you need to define it as a session state variable by the statement:
if "my_variable_name" not in st.session_state: st.session_state.my_variable_name = "xyz"
This records the variable in the program’s session state and initializes it to the value ‘xyz’
Future changes to that variable in your code must be made by the statement: st.session_state.my_variable_name = "pqr"
Now the variable will have its last assigned value across refreshes (i.e pqr).
But actually the my_variable_name =“xyz” and gets reinitalize again on hardrefeshing the page.
Could you suggest something to cope with this