===============================
Made with 💙 at OpenSourcePolitics
===============================
This project aims to provide a Marimo notebook inside Grist, as a widget.
Click "add widget to page" inside Grist, and select this widget from the URL:
https://rambip.github.io/grist-marimo-widget
Once the notebook is loaded, you can use it like any other marimo notebook.
The most important thing to understand: the entire notebook runs **in your browser** (python is translated to instructions your browser understands, thank's to [pyodide](https://pyodide.org/en/stable/)). This means that:
‼️ [click to expand] Caveats when you use a notebook inside Grist.
- The performance is limited. The memory is limted to 2G, and it will be slower than a classic notebook.
- Libraries are missing. A lot of libraries have made an effort to be packaged for browsers, but not all of them. See here for more information
- Some requests might be blocked. Since the notebook runs inside Grist, your notebook has limits regarding what sites he can communicate with. This is a security limitation, preventing that Grist widgets use information about the tables and send them to external sites. This is what CORS is about, you can read more here. But don't panic: a lot of public APIs will work seemlessly.
- there are a few more technical limitations, you can read them on marimo's website
Inside python, the grist data is available as a json file inside data.json, in the current directory.
You can read it as a dataframe, for example with pandas.read_csv("data.json")
The file will update each time you change a value in the table
[Click to expand] How autorun works
Marimo has a wonderful feature: autorun. If some cell A is updated, and another cell B depends on the result of A to do a comuptation, then B will be updated.
In order to provide the same experience with the Grist data, Grist will force the setup cell to re-run each time values in the table change. Since the setup cell executes
GRIST_DATA_PATH="data.json", this will force all the cells that useGRIST_DATA_PATHto rerun.
- if there are columns missing in the dataframes, check that all the columns you want are set as "visible" in the widget settings. This means that if you create a column, it will not be available in python unless you set it as "visible" manually.
Right now, the only way to update grist tables from marimo is to use the send_grist_actions, defined at the top of the notebook.
For more informations about how to use the userActions commands, see this post I wrote:
https://community.getgrist.com/t/a-complete-guide-for-useractions-and-action-button/13484
TODO
TODO
- Reading grist table from marimo
- Reloading cells automatically when grist values change
- Applying actions to the grist document from marimo
- Use the right color theme (light / dark)
- Add examples for using APIs and writing to the grist doc\
- Save notebook to grist options
- notebook templates
- Add a warning when the user tries to use the notebook outside grist
- import data from multiple files