Skip to content

Reload image with timer #190

Closed Answered by falkoschindler
holmesjason asked this question in Q&A
Discussion options

You must be logged in to vote

Is draw_image() returning a different URL every time? If not, the browser does not know that it needs to load a new image. It simply uses the cached image.

In a nutshell - this is what does not work:

ui.button('Update', on_click=lambda: image.set_source('https://picsum.photos/800'))
image = ui.image()

What I tend to do in such a situation is to add some URL parameter that changes every time:

ui.button('Update', on_click=lambda: image.set_source(f'https://picsum.photos/800?t={time.time()}'))
image = ui.image()

This way the URL keeps changing and the browser can't rely on its cache. But you can also use some unique ID for the image filename, i.e. the source returned by draw_image().

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by holmesjason
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants