Avoid fading output during longer background activity

Dear all!

I wrote an app to display images from a 2D detector. I use the st.experimental_rerun() function to this continuously. When using longer exposure times (seconds) the image displayed from the previous run fades as do some of the other components (I added for setting up acquisition parameters).

Is there a way to avoid this, i.e. at least the image remains displayed with the original contrasts until being replaced by the new one?

Thanks a lot in advance and for the great streamlit!

Markus

Digging further through the discussions here, I found that above topic can help me, by making components of my streamlit app be run as co-routines controlled(?) by asyncio.

Still, I shall appreciate any comment on my initial post. :slight_smile:

Thank you!
Markus

Hello @w-markus !

I don’t think it is possible to control the fading out for now. Maybe you’ll have better luck by putting the image in a placeholder and emptying it before running the rerun?

# beware, not tested code :) 
image_placeholder = st.empty()
image_placeholder.image(t)

...
if st.button("Rerun"):
    image_placeholder.empty()
    st.experimental_rerun()

Fanilo

Hello @andfanilo!
Thanks a lot, but unfortunately this does not work, as wished.

The image disappears and other components shift into the emptied space. During the time to get the next image, things (e.g. some st.write() output) fade and than the image reappears.

Markus

following up on this:

what I did in my script was, that I separated calculation/data acquisition tasks, work(), from the stuff that does the displaying via streamlit, ui(). The script first runs ẁork() followed by ui(). What I observed, was that work() blocked part of streamlit activity which resulted in grayed-out widgets.

However, I now simply reversed the sequence, i.e. first ui() and than work(), which leads to better displaying performance. It might be necessary to do a st.experimental_rerun(), though, to update things in the UI.

Another solution is the use of asynchronous routines via asyncio as describe in this discussion:

I am still wondering, what’s the speediest way to display 2D/image data using streamlit.

Best wishes
Markus