streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
34.41k stars 2.98k forks source link

st.progress with recurring timer, key and callback #7144

Open draput opened 1 year ago

draput commented 1 year ago

Checklist

Summary

Setting the st.progress in a loop when doing something slow is certainly intuitive, but how about giving the slider a timer, a callback and a key.

The timer could also be a new standalone invisible widget, e.g., st.timer(interval=1000, callback=my_callback, ...)

This would allow for example to scan an API endpoint for progress in the callback ,and set the progress value there. This would make more sense if you won't run the entire python script on any change in the frontend. I think you could still use your paradigm for interactive widgets, where the user is giving some input through the frontend, but for a progress update, which is a "pure output" widget, you could use a different paradigm (i.e. the python script won't be re-run).

I think this new paradigm (special case for pure output widgets) won't overcomplicate your nice model, you will just have to explain that the "pure output" and "input" widgets behave differently.

Without this, you either have stay in a loop updating the progress, thus blocking the python script (which has as a side effect that other widgets are dimmed), or to use st.experimental_rerun with some st.session_state and implement state-machines (certainly doable, but messier).

Thank you for your time, and keep going with your great framework! I'm a big fan!

Why?

Think about a REST API which provides an endpoint for starting a long task, and a second endpoint where you can get the progress of the long running task.

Without a timer, you either have stay in a loop querying the API and updating the progress, thus blocking the python script (which has as a side effect that it dims other output), or to use st.experimental_rerun with some st.session_state and implement state-machines (certainly doable, but messier).

How?

st.timer(interval=1000, callback=on_tick)

Ideally no python script rerun on timer callback or progress update.

Additional Context

No response

github-actions[bot] commented 1 year ago

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

CHerSun commented 1 year ago

Not completely what you want, but might be a workaround - streamlit autorefresh https://discuss.streamlit.io/t/streamlit-autorefresh/14519 .

It won't do a callback, but it will regularly rerun the script to allow updates to be displayed.

draput commented 1 year ago

Not completely what you want, but might be a workaround - streamlit autorefresh https://discuss.streamlit.io/t/streamlit-autorefresh/14519 .

It won't do a callback, but it will regularly rerun the script to allow updates to be displayed.

Thank you very much, Alexander!