File size: 1,538 Bytes
7017f6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import streamlit as st

@st.cache(suppress_st_warning=True,allow_output_mutation=True, ttl=86400)  # 86400 seconds = 1 day
#@st.cache_data(ttl=86400)  # 86400 seconds = 1 day
#@st.cache(suppress_st_warning=True, ttl=86400)
#@st.cache_data(experimental_allow_widgets=True)  # πŸ‘ˆ Set the parameter
def cache_user_data():
    return {'email': '', 'phone': '', 'password': ''}

#@st.cache_data(experimental_allow_widgets=True)  # πŸ‘ˆ Set the parameter
def main():
    st.title('User Data Caching Example')

    # Retrieve or initialize cached data
    cached_data = cache_user_data()

    # Input fields with emojis
    new_email = st.text_input("πŸ“§ Email Address", value=cached_data['email'])
    new_phone = st.text_input("πŸ“± Mobile Phone", value=cached_data['phone'])

    # Password field with an option to view contents
    show_password = st.checkbox("Show password")
    if show_password:
        new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'])
    else:
        new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'], type='password')

    # Update cache if data changes
    if new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']:
        cached_data['email'] = new_email
        cached_data['phone'] = new_phone
        cached_data['password'] = new_password
        st.success("Data updated and cached!")

    st.write("Cached Data:")
    st.json(cached_data)

# Run the app
if __name__ == "__main__":
    main()