Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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")
    time.sleep(2)

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks

>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")
    time.sleep(2)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading