Open davnat opened 2 years ago
This would be a nice way to prevent unnecessary reruns! In my case I'm waiting for altered information from an external API, in case it's different than the previous value I'd like a widget to be refreshed.
Another cool feature would be to tie the refresh functionality to a specific widget so that it only triggers a refresh of that widget instead of the entire 'page' or app. That would be neat for st.metric widgets for example.
Interesting @davnat ! Can you describe a use case here? I wonder whether conditionally including the auto refresh would solve it.
if callback():
st_autorefresh(...)
This component specifically would force a rerun of the entire script until Streamlit offers a built-in functionality to implement callbacks (a la session state). Same with updating a single widget @frankhuurman. Something interesting for Streamlit to evolve into.
Thanks for commenting on this.
My use case is:
The problem with the solution you propose is that once the callback returns False
the poll is stopped, and there's no way to restart it without a user action.
Gotcha @davnat that's an interesting problem because the rerun trigger is essentially done from the frontend, which wouldn't be able to execute your function.
I think we might need to have an update to Streamlit Custom Components to enable such a feature. :-/ I'll be sure to send the feedback to them!
Would you consider adding an optional callback to
st_autorefresh
?In my idea, the component should only refresh if the callback is
None
or if it returnsTrue