ipywidgets
ipywidgets copied to clipboard
Precompute possible outcomes of interact and include them in static HTML export
I suggest adding a feature to the Ipywidgets, that allows to precompute all possible outcomes of the function. These precomputed results should then be displayed when the user moves the slider of an interact statement. This should work even if the Jupyter notebook is exported to HTML. Let's take the following sample code:
from ipywidgets import interact
import matplotlib.pyplot as plt
import numpy as np
def f(a):
x = np.linspace(0,2,100)
plt.plot(x,a*x**2)
plt.ylim([0,20])
plt.show()
return None
interact(f, a=(1,5,1))
In the final HTML file, all possible images (in this case all parabolas with a=1...5) should be included (in this sense pre-computed) and then displayed when the user selects the appropriate value with the slider. Of course, this selection has to be done by JavaScript since for a "stand alone" HTML file no Python kernel is available. I'm aware that this can increase the file size tremendously depending on the number of possible outcomes. Nevertheless, the precomputation implemented in a handy way would improve the ipython-widgets project in my opinion.
Peter