Display HTML in swift notebooks

#1

I’m trying to the equivalent of

from IPython.display import display,HTML
out = display(HTML(some_html_code))

then later

out.update(HTML(some_new_html_code))

to work in jupyter notebook for swift (to port our progress bars there). For now

import Python
let display = Python.import("IPython.display")
var out = display.display(display.HTML(some_html_code))

gives me in the output

<IPython.core.display.HTML object>

which isn’t really what I would like to see. Any workaround this? @marcrasi

0 Likes

(Marc Rasi) #2

I will investigate why the HTML is not displaying.

Since you say you’re working on progress bars, there’s a limitation you should know about. Display messages (e.g. matplotlib plots, or this HTML stuff) only get sent to the client at the end of cell execution. If you want to have things appearing in the client during cell execution, you’ll have to print to stdout.

If updating an HTML display is very important to you, then I could implement a hacky workaround where stdouts containing a special magic string get displayed as HTML on the client.

(Details about this limitation: In order to send display messages during cell execution, we need to send ZMQ messages from the Swift process to Jupyter. To do this, we need to run the ZMQ library in the Swift process. The ZMQ library starts up its own threadpool for sending messages. LLDB (which has control over the Swift process) likes to halt these threads in sometimes, which prevents ZMQ from sending messages. So to remove this limitation, I’ll have to figure out why LLDB likes to halt the threads, and modify LLDB, and I think this might be quite difficult.)

2 Likes

#3

Agh, that’s annoying. I can do a string progress bar with print statements, but the HTML version is way nicer (and has an HTML table with the stats, and even some graphs that get plotted during training). You can see an example running here.

So the HTML not displaying isn’t important per se if it doesn’t update during training.

0 Likes

(Jeremy Howard (Admin)) #4

@marcrasi to clarify - progress bars et al aren’t a priority compared to getting a flexible training loop and optimizers working. So it’s a nice to have, but we can absolutely do the lessons without it.

0 Likes

(Jeremy Howard (Admin)) #5

Longer term question: would Xeus help avoid these issues?

0 Likes

(Marc Rasi) #6

No, because Xeus would be a different way of invoking LLDB, but LLDB would be invoking and interacting with the Swift process in the same way as it does now.

I’ll put off doing anything with HTML or display updates until the more important stuff is working well :slight_smile:

1 Like

#7

I guess a follow-up question is then, how to update a print to reprint on the same line, then.
If I do:

print(bar, terminator: "\r")

nothing gets printed at all. If I do

print("\r" + bar)

it prints all the successive progress bars.

0 Likes

(Pedro Cuenca) #8
import Glibc

for i in 0..<5 {
    print("\(i)", terminator:"\r")
    sleep(1)
    fflush(stdout)
}
0 Likes

(Pedro Cuenca) #9

Actually the sleep line should be the last in the loop, but you get the idea.

2 Likes

#10

Thanks a lot!

0 Likes