Ask Your Question
2

how to render html or latex tables in jupyter notebook?

asked 2016-09-09 14:34:33 +0100

stan gravatar image

Dear all, I moved a few of my sagenb worksheets to jupyter, but I don't seem to be able to nicely display tables. For example:

blah = [('Header1', 'Header2'), (1,2), (3,4), (5,6)]
html.table(blah)

returns the html code for the table, but does not render it. Is there a way to display a nicely typeset table in the jupyter notebook using the sage kernel? Cheers Stan

edit retag flag offensive close merge delete

Comments

Did you try pretty_print() around the html? That may be the new way to do it.

kcrisman gravatar imagekcrisman ( 2016-09-09 14:52:53 +0100 )edit
kcrisman gravatar imagekcrisman ( 2016-09-09 16:44:56 +0100 )edit

And finally, you may want to add %%html or %html at the top of such a cell and see if that gives what you want.

kcrisman gravatar imagekcrisman ( 2016-09-09 16:45:22 +0100 )edit

on sage 7.4beta1 I get in the jupyter notebook:

DeprecationWarning: use table() instead of html.table()

(and a nicely rendered html table) If I do:

table(blah)

I get the desired result immediately. I'm not sure if 7.3 already does this as well, but upgrading or waiting until 7.4 is released and then upgrading should make your life easier.

nbruin gravatar imagenbruin ( 2016-09-09 21:15:36 +0100 )edit
1

Thanks a lot! I hadn't realised that I was still running Sage 6.8, as I had problems with 7.3. I can confirm now that table(blah) displays nicely in 7.3

stan gravatar imagestan ( 2016-09-13 13:42:20 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-09-10 10:03:39 +0100

slelievre gravatar image

Just use table(blah) instead of html.table(blah).

In the Sage REPL the table will be rendered as text:

sage: blah = [('A', 'B', 'C'), (0, 1, 2), (3, 4, 5), (6, 7, 8)]
sage: table(blah)
  A   B   C
  0   1   2
  3   4   5
  6   7   8

In a Juypter notebook Sage worksheet the table will be rendered as html.

Here is a screenshot from this sage-devel post by Volker Braun.

HTML table in Jupyter notebook Sage worksheet

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-09 14:34:33 +0100

Seen: 9,257 times

Last updated: Sep 10 '16