Replies: 1 comment
-
from notebook import a_cell
a_cell.run(x=2, y=4) We might be able to simplify this to omit the You may also be interested in following this issue, for serializing pure functions at the top-level of the notebook: #2293.
Passing arguments to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been trying to understand this a bit better.
The following both work
and
What perplexes me to no end is I cannot see any way of passing arguments into the run function if I wanted a notebook that is also useable as "source code." One of the most alluring parts of Marimo is that you can have an algorithm run as a notebook, but also as a regular python file. I cannot easily however use the algorithm in other python files as python code.
I would expect this to work:
but this just gives an html output. Apparently I need to use the app script runner or the like to get outputs but can only do so in undocumented ways:
There seems to be only two ways of passing data into a notebook so far that I can tell https://github.com/marimo-team/marimo/blob/main/marimo/_runtime/context/script_context.py#L77-L87.
CLI Args are hardcoded to read from ARGV, which I guess I can spoof if required. Query params, are read, well as query params when running the notebook in a browser environment. I haven't looked further into manually setting this on the app execution environment before running it as I'm already a bit deep into private API's here.
What I would like to do is simply be able to pass in global values into the app.run() method that the notebook could then use. I've made versions of this work terribly using private api's that don't feel fantastic by executing cells manually.
This seems to work just fine. But again, it doesn't seem like this is meant to be a public API for interacting with Marimo so I'd like to avoid building on it. Am I missing something obvious here? Are folks using Marimo similarly to how I aim to here? (n.b. would it make sense to not generate html if we have no use for it in a script context?)
Naively,
@app.cell
decoration could perhaps cache the original function, and if the function is being called outside of a marimo application context, just run it as a plain python function.Beta Was this translation helpful? Give feedback.
All reactions