st.protect
or st.lock
: Option to override all widgets to disabled=True
during a process (and later discard override)
#6756
Labels
Problem
When expensive processes are initiated, a lot of care must be taken to disable widgets to prevent a user taking action during the process. This can apply to the widget initiating the process or even other widgets on the page, including "shadow widgets."
Solution
It would be nice to have some function like
st.lock()
that makes Streamlit ignore all click events. This could be in the form of iterating through all widgets it has in memory to override theirdisabled
argument toTrue
(directly or via some hidden, dominant attribute) or a higher-level act in JavaScript ignore click events in general. The locked state should end when the page completely loads (including viast.stop
) or when a companion method is called (e.g.st.unlock()
orst.lock(end=True)
).MVP: If
st.lock
is required to be called before the first widget loads on the page, Streamlit could jump ahead to iterate through all widgets in memory to disable them on the front end (taking care of shadow widgets), then proceed with the script. Then withst.lock
being active during a page load, all widgets could get silently passed an extra, dominant keyword argumentforce_disabled=True
so the widgets continue to be disabled as Streamlit executes their functions. When Streamlit gets to the end of this "locked" page load (whether actually getting to the end or callingst.stop()
), Streamlit would automatically rerun the page (erroring if it encounteredst.lock
again). With this "normal" page load the widgets would no longer be receiving theforce_disabled=True
kwarg and thus be restored to the proper state as specified in their functions.It would thus be natural to call
st.lock
as the first thing in a callback, since a rerun after a callback-prefixed load would automatically not include the callback function containing the lock.Alt MVP:
st.lock
silences all JavaScript click events within the app body. Getting to the end or callingst.unlock
undoes that silence.Possible additions: Options could be added to include/exclude naviagation links from the lock, or to lock main body widgets independently of sidebar widgets. Widgets could also all be given an kwarg
lock='exempt'
to flag a specific widget as exempt from an app lock.Additional context
#156
#6415
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.
The text was updated successfully, but these errors were encountered: