Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use updatable displays on colab?

On the Jupyter Notebook I can create named outputs that are able to be updated like this:

from IPython.display import HTML, display
import time

def progress(value, max=100):
    return HTML("""
        <progress
            value='{value}'
            max='{max}',
            style='width: 100%'
        >
            {value}
        </progress>
    """.format(value=value, max=max))

out = display(progress(0, 100), display_id=True)
for ii in range(101):
    time.sleep(0.02)
    out.update(progress(ii, 100))

progress bar

Whereas in colab it doesn't update the progress bar.

colab no updatey

How do you do this in colab?

like image 799
Kyle Kelley Avatar asked Oct 25 '17 18:10

Kyle Kelley


People also ask

How do you display a function in google Colab?

Function Documentation Colab gives you the documentation on any function or class as a context-sensitive help. Now, hit TAB and you will see the documentation on cos in the popup window as shown in the screenshot here. Note that you need to type in open parenthesis before hitting TAB.

How do you display an image in Python Colab?

Update feb/2022. In Google Colab, open the file browser icon (left nav bar) and navigate to usr/local/share/jupyter/nbextensions as described above. Click the ellipsis menu on the nbextensions folder > Upload and select your image to upload.

How do I display an image in a colab notebook?

First, open google drive & upload the image on the drive. Select the uploaded image, right-click on it, get a sharable link & copy it. Open Google Colab Notebook & add text block where you want to include the image. The general code to include an image is given below.


1 Answers

Good news! This now works in Colab. :)

(Previously, we didn't support update_display_data messages.)

Pasting the code for anyone with sharing issues:

from IPython.display import HTML, display
import time

def progress(value, max=100):
    return HTML("""
        <progress
            value='{value}'
            max='{max}',
            style='width: 100%'
        >
            {value}
        </progress>
    """.format(value=value, max=max))

out = display(progress(0, 100), display_id=True)
for ii in range(101):
    time.sleep(0.02)
    out.update(progress(ii, 100))
like image 148
Craig Citro Avatar answered Oct 21 '22 06:10

Craig Citro