Hello, I am re-opening an older post as I have difficulties understanding how a component value is displayed. I have a situation where a user get a dictionary from a database and can edit some values.
imo = st.selectbox("Select Ship IMO", [123456, 654321, 987654])
ship = fetch_ship(imo)
# fetch_ship(imo:int) -> dict is a function with a cache_data decorator
# which queries the database and returns the ship properties
L = st.number_input("Length", value = ship["L"])
# after this the user can upload the edited value
In this case if a user selects another imo number the “Length” widget will get the new default value (from the database) as expected.
Now as the user can randomly change the value (a common problem is they scroll down which interacts with the component) I thought to add a reload button, so to the user can re-load the ship and refresh the default values.
reload = st.button("Reload")
if reload:
fetch_ship.clear()
st.rerun()
But, if I click the button the widget default value remains the same. So my question is this:
What is the difference between
- selecting another
ship
(which “forces” a new default value on Length), and - just re-loading which is “like” selecting a ship, but keeps the value of the user.
I know that I can use session_state to resolve the issue. But before going to that place I want to better understand what is happening during run. Is it a bug? (as the AI bot of Streamlit docs thinks) or a feature?