Updating widgets in columns, rather than appending to column

I want to implement a dashboard which displays st.metrics across three columns. The code behind the dashboard will run a model, and these three metrics are intended to provide monitoring of how the model is running.

However when initialised as:
col1, col2, col3 = st.columns(3)

and then later updated using the following command, which is executed in a while loop:
col1.metric(‘Metric Name’, variable)

Rather than the metric value being updated in the column, the whole row is repeatedly append to the bottom of the container, meaning when this runs for 100s of iterations, I get 100s of rows of my columns.

I’ve tried adding:
col1 = st.empty()
etc.

But this overrides the st.columns command above it.

Is this intended behaviour, or is there a way to use columns to get them to update rather than append?

The solution proposed in Unable to clear or delete columns from 'beta_columns' - #4 by Charly_Wargnier did work for me (the only difference being, it didn’t need explicitly emptying the placeholder via placeholder.empty()).

Hope it works for you as well! Good luck!

1 Like

Thanks very much! the with placeholder as.... part fixed it!

1 Like

Perfect - thanks for confirming!