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
room_name = streamlit_sync.select_room_widget()
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.
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).
import streamlit as st
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