I’m sharing streamlit-sync, a library that I created to share widget states across sessions.
My use case was to be able to have multiple users running and being synchronized to the same state. This could be useful to share a same dashboard in a remote meeting, while ensuring that everyone see exactly about the same results. It makes things more interactive than a screen sharing (even though it can prove to be inefficient.
Here is a demo example I ran locally.
The API is built around a sync method that can be used around “any” existing dashboard (will probably have some issues
import streamlit_sync
room_name = streamlit_sync.select_room_widget()
with streamlit_sync.sync(room_name):
app()
Internally I’m using private APIs from streamlit, especially to access the internal session state and to trigger reruns. I manually tested the solution on streamlit 1.0.0 to 1.8.0 but I can’t ensure any robustness/security/reliability.
Another library (streamlit-server-state - discussed here) already covers part of what is doing streamlit-sync. The big difference of this new library is the possibility to sync also the state of the widgets, not only the data.
Future experimentation I want to make possible to sync the state of a streamlit app with the local drive. This should be now doable for any data that is pickle-able. The use case I see is to be able to easily experiment different sets of parameter and saving them for later reuse if needed (and keep it between restarts of the server).
Awesome! I’m especially interested in your future experiment a to save the session and to be able to continue.
Let me know if there’s a way to support you.
import streamlit as st
import streamlit_sync
CACHE_DIR = "./.st_sync_cache"
room_name = streamlit_sync.select_room_widget(CACHE_DIR)
with streamlit_sync.sync(room_name, cache_dir=CACHE_DIR):
y = st.slider("Select a value")
st.write(y, "squared is", y * y)
By default, sessions are still only synced in memory but a “cache_dir” parameter can be passed. In the backend,
What do you think about the API. Would it be convenient for you to use ? Another way I see is to have a global streamlit_sync.set_cache_dir(...) to call at the beginning of the script. It would avoid the duplicated “cache_dir” argument but also allow less modularity since it’s global.
A nice help would be to try it on your side and tell me if you encounter any problems. Since I only tested it on my example, I might be missing an important use case.
This is interesting, thanks for sharing! The first potential application that comes to mind is setting up a multiplayer game. Obviously streamlit isn’t the best framework for game dev, but maybe for games that could fit into this framework, this could allow a beginner pythonista to set up a simple multiplayer game on streamlit cloud
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.