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
7.72k stars 269 forks source link

Live refresh of marimo based on watching the filesystem #1511

Open ebetica opened 5 months ago

ebetica commented 5 months ago

Description

It would be great if we can extend marimo to work with arbitrary editors. One main gripe I've had with ipynb is being forced to use their editor. However, since marimo scripts are plaintext, it should be possible to detect filesystem changes and automatically update a UI based on code edits from another editor.

Simultaneously, this would make it much easier to do code completion with language servers in a way that it would be hard to for marimo to do, e.g. build a totally independent code editor.

Suggested solution

have a filesystem watcher run on a file, and automatically update / rerun cells as in marimo edit according to file mutations.

Alternative

No response

Additional context

No response

mscolnick commented 5 months ago

we have marimo run --watch. but this would re-run the whole application each time instead of granular updates.

this is something requested a few times and we can look into. some have referred to this as "kiosk" mode where we can edit in vscode/vim/etc, but just view the output in the browser.

I can say it is on our roadmap, but can't give you an exact time.

ebetica commented 5 months ago

I wonder if marimo can generally implement better VSCode support through the plugin. For example the VSCode editor support for editing is a lot better than marimo. The Jupyter extension on VSCode is amazing, and supports better LSP + custom environments. I don't know if there's a good way to hook up marimo to the VSCode extension for jupyter.

https://code.visualstudio.com/api/extension-guides/notebook#:~:text=The%20Notebook%20API%20allows%20Visual%20Studio%20Code%20extensions,allows%20for%20similar%20experiences%20inside%20Visual%20Studio%20Code.

mscolnick commented 5 months ago

I think very soon we will look into native vscode integration using their notebook API

majidaldo commented 2 months ago

we have marimo run --watch. but this would re-run the whole application each time instead of granular updates.

this is something requested a few times and we can look into. some have referred to this as "kiosk" mode where we can edit in vscode/vim/etc, but just view the output in the browser.

I can say it is on our roadmap, but can't give you an exact time.

this sort of works but:

cypreess commented 2 months ago

I don't know if this is the same use case, but I store some complex sql queries in separate files and I edit them separately. I would love to marimo detect this kind of dependency (or I can inform marimo explicitly) that a specific cell is dependant on a file contents, and than watch that file for changes, invalidating specific cell and re-running it (and the rest of DAG).

dmadisetti commented 2 months ago

Quick solution is to use mo.refresh to look for file changes, and then update a state variable with the new file contents when detected

Maybe this could be builtin as mo.filewatch("path") -> State? It does seem like a pretty common usecase