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
6.58k stars 226 forks source link

`marimo export html --include-code` includes pure-Markdown cells #2283

Closed patrick-kidger closed 2 weeks ago

patrick-kidger commented 3 weeks ago

Describe the bug

I'm trying to use Marimo in essentially the same way I would use Jupyter -- write some code, display the result, and add some markdown cells explaining what is going on.

I think of tutorials like this as being essentially one of the two main use-case for notebooks. (The other big one being exploratory data analysis, of course.) So I'm assuming something of this form is supported in Marimo.

Unfortunately, I can't find a way to actually do this! First of all, I believe I have to use marimo export html, as exporting is required to save output. At that point if I leave out --include-code, then none of the code is included! But if add --include-code then all of the markdown cells get duplicated (both the markdown and the underlying mo.md Python command). Furthermore in this case there is also a import marimo as mo cell orphaned at the bottom of the page.

I'm opening this as a bug report as I assume --include-code should not be duplicating things like this. (Or indeed exposing the fact that any of this was created with Marimo at all.)

Environment

{ "marimo": "0.8.14", "OS": "Darwin", "OS Version": "23.6.0", "Processor": "arm", "Python Version": "3.11.9", "Binaries": { "Browser": "128.0.6613.120", "Node": "v21.6.2" }, "Dependencies": { "click": "8.1.7", "importlib-resources": "missing", "jedi": "0.19.1", "markdown": "3.7", "pygments": "2.18.0", "pymdown-extensions": "10.9", "ruff": "0.6.4", "starlette": "0.38.5", "tomlkit": "0.13.2", "typing-extensions": "4.12.2", "uvicorn": "0.30.6", "websockets": "12.0" }, "Optional Dependencies": { "pandas": "2.2.2", "polars": "1.6.0", "pyarrow": "17.0.0" } }

Code to reproduce

No response

mscolnick commented 3 weeks ago

Thanks for outline your use-case. It's not quite a bug since it's intentional, since even markdown is actually Python code.

But I do think you have a good idea here and we can probably hide the code blocks (markdown editors) when it is just "pure markdown". We likely won't do this for interpolated markdown (for now at least).

mscolnick commented 3 weeks ago

@patrick-kidger - i have a PR (https://github.com/marimo-team/marimo/pull/2286) to remove the code if its pure-markdown.

it does not remove the import marimo as mo since we don't reliably know if its used in other cells or not. you can hide the code (in the cell action dropdown), which won't get rid of the code, but will make it at least hidden

image

something we could consider is for "hide-code", we actually hide it, instead of collapsing.

patrick-kidger commented 3 weeks ago

it does not remove the import marimo as mo since we don't reliably know if its used in other cells or not

Marimo already tracks cell-to-cell dependencies. The same mechanism could be used here?

Other than that, I appreciate the fast turnaround time! That's super useful. I'm enjoying playing with Marimo at the moment :)

mscolnick commented 2 weeks ago

@patrick-kidger I am going to close this as fixed by this PR: https://github.com/marimo-team/marimo/pull/2286

I think we need to think through hiding import marimo as mo: if we special case it or allow you to completely hide particular cells. Either way, I don't think it's a bug after this PR