Efficiently display changing table data at least every second

I going to build an internal site that displays a table with values that get frequently updated. I planned to use a websocket to send updates to javascript on the page that would update the displayed table.

I’d love to use a library instead of doing this all by hand and my search led me here. Looking in the docs, I don’t see an obvious way to handle the dynamic nature of the page.

I appreciate any feedback on whether this is an appropriate tool for the job!

Hello @marcsetgo, welcome to the community!

There are multiple workarounds for this problem and no clear winning solution yet. (The team considers building more obvious way for Streamlit apps to handle near realtime updates, but until then we’ll have to do with Python workarounds).

One of my favorites is using asyncio to drive your table updates and use a Streamlit Placeholder to update the display of the table. All native Python and no Streamlit component to build. You’ll find an example on this thread.

Don’t expect to do sub-second update though :wink:, for that you’ll probably need to do a Streamlit component and do all the updates on the JS side.

Hope this helps a bit!
Fanilo

1 Like

Thanks for the quick response. I hacked a quick dataframe with random data in a loop and that seems to work nicely.

Now I have to go learn more about the framework. I appreciate your help getting a quick POC together!

Hi there, I have an idea. Since we’ve got st.add_row() func supported for appending a row after a dataframe/table/chart… with an incremental update without causing a whole reload. Can we have a st.pop_row() to remove the first row in order to avoid booming? Otherwise, everything would become too large to show if we never stop.

That’s an interesting idea. Adding and popping rows though is still pretty cumbersome for random row updates.

For my use case, I’d much rather have the ability to update a row where some predicate matches - like a key column equal to a value. And then be able to specify updated column values for the row, or even a replacement row if that’s easier.

Thanks and have a good weekend!