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

Anywidget based widget exceeds MAX_OUTPUT_BYTES in marimo for no obvious reason #809

Closed
paddymul opened this issue Feb 25, 2025 · 5 comments
Labels
bug Something isn't working needs clarification

Comments

@paddymul
Copy link

Describe the bug

I have a widget that is throwing errors in Marimo, based on "Your output is too large". In my widget I store a large dataframe in a trait that should not be serialized to the frontend (I have separate ways of sending dataframe state).

Why would a trait without .tag(sync=True) result in the output size increasing?
Is there a way around this?

Reproduction

import pandas as pd
import numpy as np
import anywidget
import traitlets

def get_df(ROWS):
    return pd.DataFrame(
    {'int_col':np.random.randint(1,50, ROWS),
     'float_col': np.random.randint(1,30, ROWS)/.7,
     "str_col": ["foobar"] * ROWS})
    

class CounterWidget(anywidget.AnyWidget):
    _esm = """
    function render({ model, el }) {
      let button = document.createElement("button");
      button.innerHTML = `count is ${model.get("value")}`;
      button.addEventListener("click", () => {
        model.set("value", model.get("value") + 1);
        model.save_changes();
      });
      model.on("change:value", () => {
        button.innerHTML = `count is ${model.get("value")}`;
      });
      el.classList.add("counter-widget");
      el.appendChild(button);
    }
    export default { render };
    """
    _css = """
    .counter-widget button { color: white; font-size: 1.75rem; background-color: #ea580c; padding: 0.5rem 1rem; border: none; border-radius: 0.25rem; }
    .counter-widget button:hover { background-color: #9a3412; }
    """
    value = traitlets.Int(0).tag(sync=True)
    df = traitlets.Any({})

cw = CounterWidget(value=42, df=get_df(500_000))
cw

Logs

System Info

This was run against the latest version of marimo.  You can access the notebook here
https://marimo.app/#code/JYWwDg9gTgLgBCAhlUEBQaD6mDmBTAOzykRjwBNMB3YGACzgF44AiABgDoBGLjgDgC05PADcAbCzSIwYJgmSoOAQRkAKAJQY0AAWlgOAYzwAbY2mEAzOJg0AuNHEdxQkWHDCIC5RAGc4v93IHJxdoeAIAV3AAT38-AjBgx1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5UqKGOHqUn+kGAW9GF0xzDwKwbElpwyYprRgHVzACEQGZsCYUzsCQVZsFxHIla+ggNDQIA

Severity

annoyance

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

manzt commented Mar 8, 2025

I just tried the link you shared, and it seems to be working. I see a regular count output when running the provided code and no indication of MAX_OUTPUT_BYTES. I'm also not able to reproduce the issue on marimo v0.11.17.

Why would a trait without .tag(sync=True) result in the output size increasing?

It shouldn't. marimo's anywidget integration (to my understanding) correctly syncs data.

As an aside, make sure to wrap your anywidgets in marimo with mo.ui.anywidget.

@manzt manzt closed this as completed Mar 8, 2025
@manzt manzt reopened this Mar 8, 2025
@manzt manzt closed this as completed Mar 17, 2025
@paddymul
Copy link
Author

paddymul commented Mar 18, 2025

I refactored my widget around this so I'm not longer affected. But the behavior definitely exists from my testing. Did you make any code changes? A documentation update might be helpful.

@manzt
Copy link
Owner

manzt commented Mar 18, 2025

As mentioned, I do not see MAX_OUTPUT_BYTES with either the link you shared to the marimo playground nor locally with the same example as of marimo v0.11.17.

I am happy to reopen with more information and a minimum reproducible example.

@paddymul
Copy link
Author

Ugh. I just tried to reproduce and I can't. I'm sorry.

I swear I was seeing that example throw the MAX_OUTPUT_BYTES error.

@manzt
Copy link
Owner

manzt commented Mar 18, 2025

All good. Sorry for closing without an additional comment. Please let me know if it comes up again and you can reproduce.

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

No branches or pull requests

2 participants