Search code examples
jupyter-notebookipythonipywidgets

IPython: ipywidgets bug - Code working on Goolge Colab, but not on Jupyter Notebook (tested on 2 different PCs)?


This code is a "Filter as you type" textbox example. It works fine on Google Colab, but not on Jupyter Notebook. I tried it on 2 different computers (and on 2 different browsers) that have Jupyter Notebook installed and the 'out' widget only displays the textbox but nothing else. Any idea how to fix this?

I have tried pip uninstall ipywidgets then install again without success.

Thanks.

import pandas as pd, IPython.display, ipywidgets as widgets 
out = widgets.Output()


df = pd.DataFrame ({'PLAYER':['MOHAMED SALAH', 'MESSI', 'MO SALAH', 'RONALDO', 'PELE', 'PEPE', 'MANE', 'RAMREZ']})

textbox = widgets.Text(value='', description='Player:')
display(textbox)

def display_result(value):
    value = str(value['new']).upper() 
    if "{" not in value:
        result = df[(df['PLAYER'].str.contains(value))]  
        if result.shape[0]>0:
            with out:
                out.clear_output()
                display(result)

display(out)
textbox.observe(display_result)

This is the output from Google Colab:

The first picture is from Google Colab output:

This is the output from Jupyter Notebook:

enter image description here


Solution

  • I have discovered that this is caused by the "Limit Output" extension in NbExtensions. When I disabled it, the output widget worked.

    enter image description here