Skip to content

Better Marimo Support? #1018

Closed
Closed
@jsnelgro

Description

@jsnelgro

Let-plot is my favorite plotting library and for the past few weeks I've been happily experimenting with Marimo, a reactive Jupyter alternative. Unfortunately though, Lets-plot doesn't play very nicely with it. The big issues are:

  1. Charts keep getting appended to the cell output instead of modifying the chart in place (see screenshot)
  2. The output is awkwardly sized and not responsive, so you need to scroll within the iframe
  3. it's not clear how the imperative call LetsPlot.setup_html() works in a reactive environment like this (including it doesn't seem to make any difference)
  4. (less important) Marimo doesn't allow star imports, so chart declarations can be a bit harder to read

Here's an example screenshot: Screenshot 2024-02-15 at 16 44 28

And here's a minimal example Marimo notebook to reproduce the issue:

import marimo

__generated_with = "0.1.86"
app = marimo.App()


@app.cell
def __():
    import numpy as np
    import marimo as mo
    import lets_plot as lp

    lp.LetsPlot.setup_html()
    np.random.seed(42)
    return lp, mo, np


@app.cell
def __(mo):
    stddev = mo.ui.slider(1, 10, step=0.001, label="std dev")
    stddev
    return stddev,


@app.cell
def __(np, stddev):
    data = dict(
        cond=np.repeat(['A', 'B'], 200),
        rating=np.concatenate(
            (np.random.normal(0, 1, 200), np.random.normal(1, stddev.value, 200))
        )
    )
    return data,


@app.cell
def __(data, lp, mo):
    # necessary, otherwise charts keep getting appended to the frame.
    # However, this makes the cell output redraw everything on changes, causing flashes
    mo.output.clear()

    chart = lp.ggplot(data, lp.aes(x='rating', fill='cond')) + lp.ggsize(700, 300) + \
        lp.geom_density(color='dark_green', alpha=.7) + lp.scale_fill_brewer(type='seq') + \
        lp.theme(panel_grid_major_x='blank')
    chart
    return chart,


@app.cell
def __():
    return


if __name__ == "__main__":
    app.run()

I'm not sure where the easiest integration point would be (with Lets plot or Marimo?), but I figured I'd at least get it on your radar. Honestly, a quick and simple QoL improvement would just be make to_html return the html as a string if no filepath was provided.
I'm happy to take a stab at patching the to_html, to_svg, etc methods if it seems like a reasonable feature to add.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions