marimo: Reactive Notebooks for Effortless Visualizations

marimo: Reactive Notebooks for Effortless Visualizations

Motivation

Interactive data visualization and exploration are essential in data science workflows, allowing analysts and scientists to dynamically explore data and communicate findings effectively.

Working with interactive widgets in traditional notebooks requires complex widget setup, output management, and explicit function definitions for even simple interactions.

import ipywidgets as widgets

a = widgets.IntSlider(min=1, max=20)

def f(a):
    print(f'{"🍃" * a}')

out = widgets.interactive_output(f, {'a': a})

widgets.VBox([widgets.VBox([a]), out])

Introduction to marimo

marimo is a reactive notebook that automatically manages dependencies between cells and UI elements, ensuring consistency throughout the notebook.

Installation:

pip install marimo

As covered in the article about reproducible and consistent notebooks, marimo automatically re-runs dependent cells when changes occur. In this post, we will cover its interactive UI elements feature.

Interactive UI Elements

marimo simplifies the same leaf visualization with a more intuitive approach:

import marimo as mo

# Simple slider creation
leaves = mo.slider(1, 20)

# Direct output without manual widget management
mo.md(f'{"🍃" * leaves.value}')

Conclusion

marimo’s interactive UI elements provide a more intuitive and maintainable way to create interactive data applications. By automatically handling state changes and dependencies, it eliminates common sources of errors and inconsistencies found in traditional notebook environments.

Link to marimo

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran