'ipywidgets interact: set the framerate?

I have an ipywidgets.interact slider bar on a long-ish running process. This creates a situation where, when I move the slider bar, several values get buffered and I sit and wait for a while for the output to "catch up" to the point to which I've moved the slider bar. I'd like to set the number of values that get buffered when I use the slider bar.

Example:

from ipywidgets import interact
import matplotlib.pyplot as plt
import cv2
from skimage import io

image = io.imread('https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png')

@interact
def edges(low=100, high=150, aperture=3):
    plt.imshow(cv2.Canny(image, low, high, apertureSize=aperture))

Try moving the slider around and watch the image continue updating for a while after you stop. I'm on a laptop, so your mileage may vary if you have a beast of a machine.

How can I set the "framerate" to the interact function?



Solution 1:[1]

The continuous_update setting is what you want to disable for the sliders. However, I'm not 100% sure you can use it with the simple decorator approach though? Did you try this:

from ipywidgets import interact
import matplotlib.pyplot as plt
import cv2
from skimage import io

image = io.imread('https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png')

@interact(continuous_update=False)
def edges(low=100, high=150, aperture=3):
    plt.imshow(cv2.Canny(image, low, high, apertureSize=aperture))

I tried it and it works without saying there is an issue with the @interact(continuous_update=False) line. However, I'm not seeing it be slow without it, and so it is hard to test it is having the desired effect.

It is available for your sliders for sure if you define them yourself and not use the @interact route to handle giving you the sliders automatically.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wayne