(how) is it possible to update the same image on every loop of a while structure?
the used base code is that one: Examples — Python MSS latest documentation
found only this thread so far: Continuously updating dashboard
thanks in advance
(how) is it possible to update the same image on every loop of a while structure?
the used base code is that one: Examples — Python MSS latest documentation
found only this thread so far: Continuously updating dashboard
thanks in advance
One option would be to use st.fragment’s run_every
parameter along with session_state to rerun the code for generating/updating the image, like this:
import streamlit as st
from PIL import Image
if "image_step" not in st.session_state:
st.session_state["image_step"] = 0
@st.fragment(run_every=1)
def draw_image():
image_step = st.session_state["image_step"] * 10
image = Image.new(
"RGB",
(100, 100),
(
image_step,
image_step,
image_step,
),
)
st.code(f"{image_step=}")
st.image(image)
st.session_state["image_step"] += 1
if image_step > 255:
st.session_state["image_step"] = 0
draw_image()
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.