Streamlit Python – every time new line

come across Streamlit for Python. Seems to be what I want, just don’t understand, how can I keep the info all the time on the same element. Now it’s recreated each time when it runs.

import streamlit as st
import time

for x in range(10):
    st.metric(label="Temperature", value="7{} °F".format(x), delta="1.2 °F")

This is how does it look like. I want to keep just ‘redraw’ the same element. Not create a new one each time…

how does it look like


>Solution :

You need to assign the st element to a variable.
In particular, you can create an empty element:

element = st.empty()

Then, modify the element:

for x in range(10):
    element.metric(label="Temperature", value="7{} °F".format(x), delta="1.2 °F")

Leave a Reply