I found this useful (at least as a stopgap measure while waiting for
Trac#21267, which may be not as easy as it seems...), and thought that documenting this might be useful to people wanting interactive displays in Sagemath Jupyter notebooks :
The
ipywidgets python package can be installed in the Sage jupyter notebook. To enable installation "in the right place", the
installation instructions should be modified as :
sage -pip install ipywidgets
echo "jupyter nbextension enable --py --sys-prefix widgetsnbextension" | sage -sh
if you use the Sage Jupyter notebook (the original installation instructions are enough if you have installed your Sage kernel
in the system's Jupyter notebook). The following code snippet is enough to use the package :
from __future__ import print_function
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
And that's all... My limited testing seems to validate this (ab?)use of the package :
var("x,a,b")
dbeta(x,a,b)=x^(a-1)*(1-x)^(b-1)/beta(a,b)
def showbeta(a,b):
show(plot(dbeta(x,a,b),(x,0,1),figsize=4))
return(None)
interact(showbeta,
a=widgets.FloatSlider(min=0.0,max=10.0,step=0.1,value=1.0,continuous_update=False),
b=widgets.FloatSlider(min=0.0,max=10.0,step=0.1,value=1.0,continuous_update=False));
Note that the ipywidget package has no way to use a lot of Sage data types. Any argument to them have to be cast to
native python data types (int, float, string).
Clunky, but damn useful, at least for pedagogic purposes...
HTH,
--
Emmanuel Charpentier