marimo
marimo copied to clipboard
Sidebar doens't render if cells block on initialization
Describe the bug
If a/some cell(s) in the marimo app take a long time to initialize (could be some database transfer, file reading etc), then, for whatever reason, the sidebar doesn't show up when running marimo run app.py.
Environment
{ "marimo": "0.5.2", "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": "v14.16.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", "websocket": "missing", "typing-extensions": "4.9.0", "black": "24.3.0" } }
Code to reproduce
here's a minimal repro, where one cell sleeps for 2 seconds to emulate a blocking thread (like an i/o operation)
import marimo
__generated_with = "0.5.2"
app = marimo.App(layout_file="layouts/sidebar.grid.json")
@app.cell
def __():
import marimo as mo
from time import sleep
return mo, sleep
@app.cell
def __(mo):
mo.sidebar(
[
mo.md("World"),
mo.ui.switch()
]
)
return
@app.cell
def __(mo, sleep):
sleep(2) # emulate blocking
mo.md("Hi")
return
if __name__ == "__main__":
app.run()
what happens if you move the sidebar creation to the first cell? it's likely that the blocking cell is run first, since its a tie between the second and third cell, we don't force the sidebar to render before the other.
we do plan on adding parallel execution at some point, but in the mean time, can you force the sidebar to be first by forcing it in the dependency graph.
e.g.
# Cell 2
sidebar = mo.siderbar(...)
sidebar
# Other cells
sidebar
sleep(2)
mo.md("hi")
It may be a bit difficult in practice, since apps may have many cells, and knowing which order they are executed in should be the purpose of marimo, and not the user's to guess. However, I still don't understand why the sidebar doesn't eventually render, even if cell 3 is executed before cell 2.
However, I still don't understand why the sidebar doesn't eventually render, even if cell 3 is executed before cell 2.
@mrdobalina2k is this while editing. this is something i don't experience. i see it show after 2 seconds.
Going to close this as we now tie-break cells by top-down. So the sidebar will only be blocked on its dependencies.