streamlit-image-coordinates icon indicating copy to clipboard operation
streamlit-image-coordinates copied to clipboard

Reloading image after getting the value

Open vrtulka23 opened this issue 1 year ago • 5 comments

I use the clicked coordinates to display points on the image. However, currently the image is being displayed before I get the "value" and I have to reload the script in order to show changes on the image. This leads to a very annoying flickering after each click. It would be nice to have an option to update the image immediately after acquiring the coordinate values.

vrtulka23 avatar Jun 14 '24 11:06 vrtulka23

Just to clarify. Ideally, one should avoid using "st.rerun()" to update the image, because it flickers and the whole experience looks unprofessional. Cannot you use e.g. st.empty() in the module to clear and refresh the image?

st.empty()

vrtulka23 avatar Jun 17 '24 09:06 vrtulka23

I have an idea how to solve this. You could update image URL in this method by simply adding "?salt=<random_number>" into the following method: https://github.com/blackary/streamlit-image-coordinates/blob/1ecfe31d4fd6e05508f2673c810cdaa779ae23e1/src/streamlit_image_coordinates/frontend/main.js#L16

This would force the browser to reload the image every time user click on it and load the newest version.

vrtulka23 avatar Jun 17 '24 12:06 vrtulka23

+1 on this. Using st.rerun works as mentioned here, but it's very annoying to use as the screen flickers on very click

Shade5 avatar Sep 08 '24 18:09 Shade5

@blackary, Is it possible to add an on_click callback parameter to streamlit_image_coordinates() that somehow provides access to coordinates as well?

AliKhoda avatar Mar 26 '25 15:03 AliKhoda

Yes, if we're willing to limit to streamlit>=1.36.0, custom components can have an on_change, which seems like a good idea to me. It would make this problem much simpler to solve.

blackary avatar Mar 27 '25 18:03 blackary