Interactive ipywidgets tool doesn't show in Kaggle

Hi all,

I’m going through Chapter 6 notebook : How random forests really work | Kaggle notebook editing and running my own copy in Kaggle.

The interactive tool in the code block doesn’t show up for me now.

def iscore(nm, split):
col = trn_xs[nm]
return score(col, trn_y, split)

from ipywidgets import interact
interact(nm=conts, split=15.5)(iscore);

It was previously showing up fine. I previously had Ubuntu 18.04 and now I have installed Ubuntu 24.04 on my system. Unlikely that this could cause an issue within Kaggle, but just mentioned that anyway.
Using Google Chrome browser (Version 131.0.6778.69)
The same behaviour was seen in Firefox too.

Also, after the initial few cells, the cells don’t show the run button on hovering to the left of the cell.

There are quite a lot of errors / warnings in console
But this one seems related

renderShadowDOM.tsx:637 Uncaught TypeError: window.setImmediate is not a function
at h (renderShadowDOM.tsx:637:14)
at animationFrameDelay.ts:28:9

Attached a screenshot

Any help to resolve this would be much appreciated. Thanks

There seems to be some issue with ipython widgets in Kaggle associated with a recent upgrade, detailed here : [Product update] JupyterLab 4 in Kaggle Notebooks | Kaggle

Based on the suggestions there, modified the code to the below.
The slider is shown, but return value (i.e. score) isn’t shown

from ipywidgets import interactive, interact
from ipywidgets.embed import embed_minimal_html
from IPython.display import display, IFrame
def sidescore(side, y):
    tot = side.sum()
    if tot<=1: return 0
    return y[side].std()*tot
def score(col, y, split):
    lhs = col<=split
    return (_side_score(lhs,y) + sidescore(~lhs,y))/len(y)
def iscore(nm, split):
    col = trn_xs[nm]
    return score(col, trn_y, split)
ii = interactive(iscore, nm=conts, split=15.5)
# Generate the HTML for the widget
embed_minimal_html('export1.html', views=[ii], title='Widgets export')
# Display the HTML file in an iframe
display(IFrame(src='export1.html', width=400, height=100))

Arrived at the below based on interaction with Claude, but still return value isn’t shown

from ipywidgets import interactive, interact, widgets, VBox, HBox, Layout, HTML
from ipywidgets.embed import embed_minimal_html
from IPython.display import display, IFrame
import json

def _side_score(side, y):
    tot = side.sum()
    if tot <= 1: 
        return 0
    return y[side].std() * tot

def score(col, y, split):
    lhs = col <= split
    return (_side_score(lhs, y) + _side_score(~lhs, y)) / len(y)

# Create a FloatText widget to display the score
score_display = widgets.FloatText(
    description='Score:',
    disabled=True,
    layout=Layout(width='200px')
)

def iscore(nm, split):
    col = trn_xs[nm]
    result = score(col, trn_y, split)
    score_display.value = result
    return result

# Create the interactive widget
ii = interactive(iscore, nm=conts, split=15.5)

# Combine the widgets
combined_widget = VBox([
    ii,
    score_display
])

# Generate the HTML
embed_minimal_html('export1.html', views=[combined_widget], title='Widgets export')

# Display in iframe
display(IFrame(src='export1.html', width=400, height=200))

Leaving it at that :sweat_smile: