Thanks Goyo
A slight change to the example from the documentation suited my needs.
Below is the modified example.
I need to keep the same date range in the sidebar for all the pages of my app.
But a change to the date range needs to be taken into account only
when st.date_input really returns a range. Otherwise, the app should wait next iteration.
This tiny thing was the reason of my headache!
Probably because it was entangled with the rest of the logic, other parameters that may need to trigger some calculations.
I still have to get used to the Streamlit’s execution model !
Thanks again, you helped a lot!
Michel
PS:
By the way, if the app execution was delayed untils the date_input actually returned a range (as specified in the initial value), I would even not have had to care!
Would it be difficult to create a date_range_input widget, or the like?
But adding “if len(d)==2:” was not too difficult !!!
Modified example for a date range using st.date_input
import streamlit as st
from datetime import date
jan_1, dec_31 = (date(2023, 1, 1), date(2023, 12, 31))
jan_rg = (date(2023, 1, 13), date(2023, 1, 17))
if st.session_state:
d = st.session_state.d
else:
d = jan_rg
d = st.date_input("Select a range", value=d, min_value=jan_1, max_value=dec_31)
if len(d)==2:
st.session_state.d = d
d