jrieke / streamlit-analytics

👀 Track & visualize user interactions with your streamlit app
MIT License
262 stars 48 forks source link

AttributeError: st.session_state has no attribute "last_time". #33

Open rawmean opened 1 year ago

rawmean commented 1 year ago

I get the following error:

AttributeError: st.session_state has no attribute "last_time". Did you forget to initialize it? More info: https://docs.streamlit.io/library/advanced-features/session-state#initialization

It comes from this line. The fix seems to be easy (avoid using the dot notation when the key doesn't exist)

    if "last_time" not in st.session_state:
        st.session_state.last_time = datetime.datetime.now()
    _track_user()
nbora0911 commented 6 months ago

@rawmean How did you patch this in your code without streamlit-analytics having pushed it?

rawmean commented 6 months ago

@rawmean How did you patch this in your code without streamlit-analytics having pushed it? Try this: ''' if "last_time" not in st.session_state: st.session_state[last_time] = datetime.datetime.now() _track_user() '''