Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental features (widget decorator) not working in Marimo #792

Open
guiferviz opened this issue Feb 10, 2025 · 3 comments
Open

Experimental features (widget decorator) not working in Marimo #792

guiferviz opened this issue Feb 10, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@guiferviz
Copy link

guiferviz commented Feb 10, 2025

Describe the bug

Thank you so much for this library!

It seems that the experimental API isn't working properly on Marimo. I created a minimal plugin using both the stable and experimental APIs, but the experimental version isn't rendering. Marimo is showing the error: Unsupported mimetype: application/vnd.jupyter.widget-view+json. I'm not sure if this issue is related to Marimo or Anywidget, so I'm posting it here first for feedback.

Image

Reproduction

import marimo

__generated_with = "0.11.0"
app = marimo.App(width="medium")


@app.cell
def _():
    import marimo as mo
    return (mo,)


@app.cell
def _(mo):
    mo.md(r"""# Classic""")
    return


@app.cell
def _():
    import anywidget
    import traitlets
    return anywidget, traitlets


@app.cell
def _(anywidget, traitlets):
    class MinimalWidget(anywidget.AnyWidget):
        _esm = """
            function render({ model, el }) {
                el.textContent = `Value: ${model.get('value')}`;
                model.on('change:value', () => {
                    el.textContent = `Value: ${model.get('value')}`;
                });
            }
            export default { render };
        """
        value = traitlets.Int(0).tag(sync=True)

    MinimalWidget(value=3)
    return (MinimalWidget,)


@app.cell
def _(mo):
    mo.md(r"""# Experimental""")
    return


@app.cell
def _():
    import pydantic
    import psygnal
    from anywidget.experimental import widget
    return psygnal, pydantic, widget


@app.cell
def _(psygnal, pydantic, widget):
    @widget(
        esm="""
            function render({ model, el }) {
                el.textContent = `Value: ${model.get('value')}`;
                model.on('change:value', () => {
                    el.textContent = `Value: ${model.get('value')}`;
                });
            }
            export default { render };
        """
    )
    @psygnal.evented
    class MinimalWidgetExperimental(pydantic.BaseModel):
        value: int = 0

    MinimalWidgetExperimental(value=3)
    return (MinimalWidgetExperimental,)


if __name__ == "__main__":
    app.run()

You can run previous code with marimo edit file.py.

Logs

Unsupported mimetype: application/vnd.jupyter.widget-view+json

No logs in terminal.

System Info

Dependencies:

$ uv pip freeze | grep -E "anywidget|jupyter|notebook"
anywidget==0.9.13
jupyterlab-widgets==3.0.13


System and browser:

  System:
    OS: macOS 14.7.3
    CPU: (16) arm64 Apple M3 Max
    Memory: 15.65 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 133.0.6943.54

Severity

annoyance

@guiferviz guiferviz added the bug Something isn't working label Feb 10, 2025
@manzt
Copy link
Owner

manzt commented Feb 10, 2025

Hey there! Thanks for opening the issue. Yes, the integration on marimo's end currently requires some Python code to interface with anywidget.AnyWidget (i.e., traitlets). So, unfortunately this is expected behavior in state of the experimental API.

Ideally, we'd have a way to marimo (and others) to hook into whatever reactivity system is used (probably a protocol).

@guiferviz
Copy link
Author

Interesting. I thought that the purpose of using @psygnal.evented was to replace traitlets. I am obviously not familiar with the inner workings of anywidgets or Python widgets in general.

Thank you for your prompt response, and please feel free to close the issue if you think it's appropriate!

@manzt
Copy link
Owner

manzt commented Feb 10, 2025

No worries! Yes, the goal of the experimental api is to decouple the way you model state and emit events to/from the front end. Right now all of the (Jupyter) widgets ecosystem is tied to a traitlets-based based class from ipywidgets.

My first goal is to replace anywidget.AnyWidget with a base class that is based on the descriptor-based API and protocol for getting/setting state. We can then have marimo and others like shinywidgets connect to the comms channel and be agnositc of the underlying model / event emitter representation.

I'm going to keep this open in case someone else has the same question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants