I found this useful (at least as a stopgap measure while waiting for 
Trac#21267 <https://trac.sagemath.org/ticket/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 <https://github.com/ipython/ipywidgets> python package can 
be installed in the Sage jupyter notebook. To enable installation "in the 
right place", the installation instructions 
<http://ipywidgets.readthedocs.io/en/latest/user_install.html#with-pip> 
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_functionfrom ipywidgets import interact, 
interactive, fixedimport 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

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to