Get help from the marimo community

Updated last week

Reactive Matplotlib Figure Across Cells

I need one cell to load a file browser and open the file and another cell to plot the data. I cannot figure out how to get the 2nd cell to resolve the dependency on the first. Here is my code:

Plain Text
@app.cell
def _(mo, np):
    def handle_file_select(info):
        global img
        for f in info:
            img = np.load(f.path)["arr_0"]

    mo.ui.file_browser(
        initial_path="/mnt/notchpeak/transfer/new_worms/",
        on_change=handle_file_select,
        multiple=False,
    )

    return img


@app.cell
def _(plt, img):
    if img is not None:
        plt.imshow(img)
        plt.tight_layout()
        plt.show()
Add a reply
Sign up and join the conversation on Discord