You need to introduce state for that, either have a look here for an example (if you search state streamlit there are various non official implementations around):
Or use the new feature of 0.65 for query_params
https://github.com/streamlit/release-demos/blob/release-0-65-0/demos/query_params.py