[Bug?] Streamlit date_input on different page accidentally sharing same value

Summary

I have two date_input objects on two pages. I expect those two items’ value will not be impacted by the operation on each other. However, by changing the footprint_date on page1 (1_p1), the st.write on page2 (2_p2) also gets changed to the selection I made on page1, and the value on the date box shows something different than the actual value of footprint_date. Could I get an explanation of why this happened?
(E.g. changing the date_input on page1 to Aug 18th, the st.write() on page2 returns Aug 18th but the value in date_input is Aug 28th. Shouldn’t the st.write on page2 be Aug 28th?)

Steps to reproduce

Code snippet:
1_p1.py

import streamlit as st
import datetime
footprint_date = st.date_input('Coverage Date', value=datetime.date(2023,8,28),
                                      min_value=datetime.date(2023,8,18),
                                      max_value=datetime.date(2023,8,28), format="YYYY/MM/DD")
st.write(footprint_date)

2_p2.py

import streamlit as st
import datetime
footprint_date = st.date_input('Coverage Date', value=datetime.date(2023,8,28),
                                      min_value=datetime.date(2023,8,18),
                                      max_value=datetime.date(2023,8,28), format="YYYY/MM/DD")
st.write(footprint_date)

Thanks for your help!

1 Like

May be this will help you

import streamlit as st
import datetime
def main():
    page = st.sidebar.selectbox("Select a page", ["Page 1", "Page 2"])
    if page == "Page 1":page_content("page1")
    else:page_content("page2")
def page_content(page_key):
    key = f"footprint_date_{page_key}"
    if key not in st.session_state:
        st.session_state[key] = datetime.date(2023, 8, 28)
    footprint_date = st.date_input('Coverage Date', value=st.session_state[key],
                                   min_value=datetime.date(2023, 8, 18),
                                   max_value=datetime.date(2023, 8, 28), format="YYYY/MM/DD")
    st.session_state[key] = footprint_date
if __name__ == "__main__":main()

Hi @IM45145V,

I know how to solve this issue - giving a unique key value for each of the date_input can solve it.
However, I am more interested in what is the reason behind this behaviour. Is this a bug? Or is this reasonable? Are there any other components having same issues as this one?

Thanks.