I have a local version of my app working without any errors, but encounter a few different errors when hosting on Streamlit Cloud and have found it hard to troubleshoot after going through the documentation. Can anyone assist in better understanding how to utilize the @st.cache for the following use case?
- User enters a stock ticker and the app runs a few functions (load_data, options_chain, and load_main_chart)
- Each of these functions have the decorator @st.cache(allow_output_mutation=True)
- These functions store data in dataframes and display tables and charts based off these dataframes.
- Users can interact with streamlit input widgets to modify these displays (which seemed to be the necessity for allow_output_mutation=True)
- The only time the functions need to re-run is when a different ticker is selected and/or when a different time range for the data is selected. Hence, the user should be able to manipulate displays with the cached data (this is how I understand it should work).
- Multiple users should be able to access simultaneously and not interfere with other users session. It does not seem session states were required based on how I am understanding the caching mechanism.
On a side note, I’ve tried @st.experimental_memo but received error messages when replacing the standard @st.cache with this. I am also unsure what would be best practice to make the app usable by multiple users (for streamlit cloud public) as far as memory goes. Should all variables be deleted after each function executes? Does the cache build up indefinitely as new users try out the app?
Some of the errors on Streamlit Cloud include:
- Specific tickers throw this error such as “HD”: *File “/home/appuser/venv/lib/python3.7/site-packages/pandas/core/indexes/base.py”, line 3785, in _validate_can_reindex raise ValueError(“cannot reindex from a duplicate axis”)
- When testing different user sessions the dataframe built from cache is based on the time that each user loads the data. Sometimes a user may need to refresh their data so I am using a streamlit button that executes: st.legacy_caching.clear_cache() to clear the cache and re-run the app. This works sometimes, but other times it either doesn’t work or bogs down the app indefinitely until I reboot.
- Also certain functions appear to run much faster on local version, such as (option_chain).
- Lastly, it seems after multiple users had tested the whole app triggered an error related to not being able to access an element from the cache.