marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
5.39k stars 158 forks source link

Output goes stale in run and edit mode (app view mode) #1587

Open mrdobalina2k opened 3 weeks ago

mrdobalina2k commented 3 weeks ago

Describe the bug

I'm building an app to run calculations. The calculations take time. Therefore, I decided to place a spinner to show the progress (status). However, instead of showing the spinner clearly when I click the calculate button, the output is marked as stale, and greyed out, though I can see the changing status in the background.

Environment

{ "marimo": "0.6.17", "OS": "Windows", "OS Version": "11", "Processor": "Intel64 Family 6 Model 126 Stepping 5, GenuineIntel", "Python Version": "3.12.2", "Binaries": { "Browser": "123.0.6312.123", "Node": "v20.14.0" }, "Requirements": { "click": "8.1.7", "importlib-resources": "missing", "jedi": "0.19.1", "markdown": "3.6", "pymdown-extensions": "10.7.1", "pygments": "2.17.2", "tomlkit": "0.12.4", "uvicorn": "0.29.0", "starlette": "0.37.2", "websockets": "11.0.3", "typing-extensions": "4.9.0", "black": "24.3.0" } }

Code to reproduce

Here's the code to reproduce.


import marimo

__generated_with = "0.6.17"
app = marimo.App(width="medium", layout_file="layouts/stale_output.grid.json")

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

@app.cell
def __(asyncio):
    async def generator():
        nmax = 10
        for i in range(1, nmax+1):
            yield f"completed {i} out ouf {nmax}"
            await asyncio.sleep(2)
        return
    return generator,

@app.cell
def __(mo):
    run_button = mo.ui.run_button()
    run_button
    return run_button,

@app.cell
async def __(generator, mo, run_button):
    run_button
    if run_button.value:
        with mo.status.spinner("Calculating") as _spinner:
            async for status in generator():
                _spinner.update(subtitle=status)

    mo.output.replace(mo.md("Waiting"))
    return status,

if __name__ == "__main__":
    app.run()
akshayka commented 3 weeks ago

Thanks for reporting. Started investigating — this appears to be specific to grid layout. I can't repro in the vertical layout