How does one pump text into a scrolling window in streamlit?

Viewed 508

I have seen streamlit display scrolling text windows. In particular, they get displayed for dataframes.

Is there a way to somehow write incrementally to a, for example scrolling info, warning and error text window with the same color codes as the info, warning and error text lines written to the screen with streamlit.info("foo"), streamlit.warning("bar"), && streamlit.error("foobar")?

1 Answers

Not sure exactly what you mean by a scrolling text window, but using the st.empty(), you can continuously write over the same object, which gives the effect of what I think you're asking for:

import streamlit as st
import time

c = st.empty()

for i in range(1, 30):
    time.sleep(0.5) #just here so you can see the change
    c.text(i)

This example can be extended to anything where you can consistently append/pop data off a list, indexing, etc.

Edit: note that what I'm referring to as c here ends up being the generic Streamlit class that contains most/all of the widgets. So text could be swapped out for dataframe, metric and any number of other Streamlit widgets.

Related