I’m hosting a Streamlit Chat app on Azure and want to persist logs to Blob Storage for later analysis. However, connecting to Blob Storage significantly slows down the site load time. My priority is to make the site load as quickly as possible, so I’m open to delaying the connection until it’s genuinely needed. Ideally, I’d like to trigger this connection only on demand—perhaps with a button or another user action that initiates the transfer to Blob Storage.
I’ve tried using a button that only attempts to connect when pressed, but unfortunately, there’s still a considerable delay every time the blob connection needs to be re-established, even if the button is untouched.
Currently, the best workaround I’ve managed is creating an app.py wrapper and placing my chat code in a streamlit_pages folder. app.py then manually loads all the pages like this:
ask_question_page = st.Page("streamlit_pages/1_answer.py", title="Ask a question", default=True, icon=":material/forum:")
toc_question_page = st.Page("streamlit_pages/2_table_of_content.py", title="Table of content", icon=":material/list:")
documentation_page = st.Page("streamlit_pages/5_Read_the_Documents.py", title="Read the documents", icon=":material/article:")
pg = st.navigation({"Other things to do": [ask_question_page, toc_question_page, documentation_page]})
pg.run()
setup_log_storage(st.session_state['blob_name_for_session_logs'])
This setup allows the app to load visually while establishing the Blob connection after all the visual elements are loaded, so users can view the app’s full interface without being distracted by loading components. However, while the app looks fine, it remains unusable until the connection is fully established.
Does anyone have suggestions for a more efficient way to delay the Blob Storage connection to avoid impacting the user experience?