jupyterlite / pyodide-kernel

Python kernel for JupyterLite powered by Pyodide
https://jupyterlite-pyodide-kernel.readthedocs.io/en/latest/_static/
BSD 3-Clause "New" or "Revised" License
45 stars 23 forks source link

ipywidgets does not work in some situations #133

Open MRYingLEE opened 1 month ago

MRYingLEE commented 1 month ago

For the following simple ipywidgets code:

%pip install ipywidgets
# Import IPython widgets for interactive input
from IPython.display import display
import ipywidgets as widgets

# Create a text box for user input
prompt_box = widgets.Textarea(
    value='Enter your prompt here...',
    placeholder='Type something...',
    description='Prompt:',
    disabled=False
)

# Create a button to generate text
button = widgets.Button(description="Generate Text")

# Function to handle button click
def on_button_click(b):
    prompt = prompt_box.value
    generated_text = "generate_text(prompt)"
    print("Prompt:", prompt)
    print("Generated Text:", generated_text)

# Attach the function to the button click event
button.on_click(on_button_click)

# Display the text box and button
display(prompt_box, button)

I works well in other Jupyter environment, such as Colab (https://colab.research.google.com/). image

But the button clicking does not show anything in Jupyterlite, such as here (https://jupyterlite-pyodide-kernel.readthedocs.io/en/latest/_static/lab/index.html).

Please check. Thanks,

MRYingLEE commented 1 month ago

I used kernelspy(https://github.com/jupyterlab-contrib/jupyterlab-kernelspy) to check the messages after the button was clicked, and I saw: image

So it seems the messaging system worked well but for some reason the messages were not processed well.

MartinaMJ commented 3 weeks ago

Hello. I have been facing this same problem. I noticed the kernel responds to the first few interactions but then stops responding. Did you find a solution or a possible cause?