ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 17 Oct 2020 17:00:38 -0500%display latex vs. ipywidgetshttps://ask.sagemath.org/question/53950/display-latex-vs-ipywidgets/This is part informational and part a question of style
In Sage Manifolds, `%display latex` is set to produce "pretty" output like thus
%display plain
var('a, g')
display(sqrt(a + g))
%display latex
sqrt(a + g)
which everybody knows, but a more insidious thing is that it breaks `ipywidgets.Hbox()` "display".
I did a hack in this code below; but does anybody know of a more elegant (re. automatic) means.
This is a little long but illustrates what is lost. Try changing `%display` lines at the bottom.
%display latex # Just to copy the problem in
import matplotlib.pyplot as plt
from IPython.display import display, HTML
import ipywidgets
# Save
file_name = 'rings.html'
save_desc = 'save as' + file_name
save_box = ipywidgets.Checkbox(False, description=save_desc)
# Red ring
red_ring = Horizon()
red_box=red_ring.box(desc='red ring')
red_ring.color = 'red'
red_ring.radius =2
# Black ring
black_ring = Horizon()
black_box = black_ring.box(desc='black ring')
black_ring.color = 'black'
black_ring.radius = 3
# Green ring
green_ring = Horizon()
green_box = green_ring.box(desc='green ring')
green_ring.color = 'green'
green_ring.radius = 4
ui = ipywidgets.HBox([red_box, black_box, green_box, save_box])
def f(red, black, green, save_f):
global plt_obj
plt_obj = sphere((1, 0, 0), .6)
if red:
plt_obj += red_ring.gobject()
if black:
plt_obj += black_ring.gobject()
if green:
plt_obj += green_ring.gobject()
if save_f:
save(plt_obj,file_name)
show(plt_obj, viewer='threejs')
out_show = ipywidgets.interactive_output(f, {'red': red_box,
'black': black_box,
'green': green_box,
'save_f' : save_box})
%display plain
display(ui)
display(out_show)
%display latexrrogersSat, 17 Oct 2020 17:00:38 -0500https://ask.sagemath.org/question/53950/SageMath and interact / ipywidgets with jupyterhttps://ask.sagemath.org/question/41269/sagemath-and-interact-ipywidgets-with-jupyter/I got the SageMath kernel working well inside my anaconda distribution's copy of jupyter, following [these instructions](https://stackoverflow.com/a/41595015), so I can open SageMath notebooks using anaconda jupyter and they run perfectly fine -- almost.
I would like to get interact elements / ipywidgets working when I use SageMath as a kernel in anaconda jupyter, but with my current configuration (hopefully described in sufficient detail below), I get the following error message in the console
>[IPKernelApp] WARNING | Widget Javascript not detected. It may not be installed or enabled properly.
and the notebook simply outputs the initial value of the function with no interactivity.
---
I'm running SageMath 8.1 on macOS. I've been able to get interact elements and ipywidgets with SageMath code running in the SageMath jupyter notebook interface (not sure if this was necessary, but I ran
`/local/bin/jupyter nbextension enable --py widgetsnbextension`
in the SageMath directory.) Everything works as expected, i.e. if I run `sagemath -n jupyter` and open a notebook containing:
>import ipywidgets as widgets
>
>widgets.IntSlider(
value=7,
min=0,
max=10,
step=1,
description='Test:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
I get a slider widget which works.
Similarly, examples from this [interact tutorial](https://wiki.sagemath.org/interact/graphics) on the SageMath wiki run perfectly fine in SageMath jupyter.
I also have an up-to-date anaconda install of jupyter where the ipywidgets nbextension has been enabled; the above ipywidgets code can be run in anaconda jupyter with the ordinary python kernel and works fine.
----
[The real reason I am asking this question is I would like to figure out how to get interactive widgets working in jupyterlab with the SageMath kernel, but I'm guessing that if the above question can be answered, I can get everything else working as well.]j.c.Mon, 26 Feb 2018 12:16:26 -0600https://ask.sagemath.org/question/41269/Sage on Jupyter with ipywidgets, matplotlibhttps://ask.sagemath.org/question/31326/sage-on-jupyter-with-ipywidgets-matplotlib/Hi all,
I've spent about two days now trying to get Sage to work nicely on Jupyter.
Still, I have the following two problems:<br /><br />
1. ipywidgets (and I have found no docu on the web that would hint to this problem) does not show any output and fails on commands like interact(f,x=10)<br /><br />
2. backend support for matplotlib (I've tried all the "solutions" that come up on a google search, I have tk/tcl installed on my system, sage compiled from scratch with $SAGE_MATPLOTLIB_GUI="yes" but it does not find TKInter for tk support, not to mention that the sage pyqt4 package fails compiling)
**concerning 1.**<br />
I ran the following code on jupyter with Sage 6.9 kernel
from __future__ import print_function;
from ipywidgets import interact;
def f(x): return(x);
interact(f,x=10);
this gives (besides various traceback output)
ValueError: 10 cannot be transformed to a Widget
I have the following version:
sage -installed | grep ipywidgets
ipywidgets.............................. 4.0.2
**concerning 2.**<br />
I've tried to recompile sage -f matplotlib after export SAGE_MATPLOTLIB_GUI="yes"
BUILDING MATPLOTLIB
matplotlib: yes [1.4.3]
python: yes [2.7.9 (default, Dec 3 2015, 20:58:38) [GCC
4.8.4]]
platform: yes [linux2]
...
OPTIONAL BACKEND EXTENSIONS
macosx: no [Mac OS-X only]
qt5agg: no [PyQt5 not found]
qt4agg: no [PyQt4 not found]
pyside: no [PySide not found]
gtk3agg: no [Requires pygobject to be installed.]
gtk3cairo: no [Requires cairocffi or pycairo to be installed.]
gtkagg: no [Requires pygtk]
tkagg: no [TKAgg requires Tkinter.]
wxagg: no [requires wxPython]
gtk: no [Requires pygtk]
agg: yes [installing]
cairo: no [cairocffi or pycairo not found]
windowing: no [Microsoft Windows only]
running on:
> uname -a
Linux host 3.16.0-53-generic #72~14.04.1-Ubuntu SMP Fri Nov 6 18:17:23 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
> locate libtk8.6.so
/usr/lib/x86_64-linux-gnu/libtk8.6.so
> locate libtcl8.6.so
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
> locate Tkinter.py
/usr/lib/python2.7/lib-tk/Tkinter.py
/usr/lib/python2.7/lib-tk/Tkinter.pyc
Furthermore, (on another machine for some magic reason I could not figure out, I have TKAgg as backend available), it seems I cannot use %matplotlib inline as with a python kernel. The only option seems to have the plots in a new window.
Can anybody help? I'm frustrated to the point that I'm nearly planning on using the Python kernel and running the needed sage code via exec. But, quite honestly, that would be horrendous ;-)camoldFri, 04 Dec 2015 12:27:10 -0600https://ask.sagemath.org/question/31326/