Back to Skills

anywidget-generator

Generate anywidget components for marimo notebooks.

147stars12forksUpdated 6/16/2026

Security Assessment

Safe(90/100)

Detected risks:

Sensitive File Access([SKILL.md] .env)
Security Score90/100

About anywidget-generator

The anywidget-generator skill helps developers create custom interactive widgets for marimo notebooks using the anywidget framework. It streamlines the process of building bidirectional Python-JavaScript components by providing guidance on proper structure, styling, and integration patterns. This skill solves the challenge of creating rich, interactive visualizations and controls within marimo notebooks without requiring deep expertise in widget development frameworks.

The skill emphasizes vanilla JavaScript implementation in the `_esm` module and responsive CSS styling in `_css` that adapts to both light and dark modes. It supports both inline code for simple widgets and external file references using pathlib for more complex implementations. The generator ensures proper trait synchronization between Python and JavaScript, handles model updates with `model.set()` and `model.save_changes()`, and provides patterns for listening to state changes. All widgets are properly wrapped with marimo's `mo.ui.anywidget()` for seamless notebook integration.

This skill is ideal for data scientists, researchers, and developers building interactive marimo notebooks who need custom UI components beyond standard offerings. Common use cases include creating custom data visualizations, building domain-specific controls, prototyping interactive dashboards, and developing reusable widget libraries. The skill prioritizes simplicity and clarity, encouraging straightforward implementations over complex abstractions to ensure maintainability and ease of understanding for developers of varying experience levels.

FAQ

When should I use external files versus inline code for _esm and _css?

Use inline code for simple widgets with minimal JavaScript and CSS. For widgets with elaborate JavaScript logic or extensive styling, use external files referenced via pathlib. This keeps your code organized and maintainable, especially as complexity grows.

How do I make my widget work in both light and dark modes?

Include CSS media queries for dark mode using `@media (prefers-color-scheme: dark) { ... }`. Define appropriate color schemes for both modes. Keep styling minimal unless specifically asked to provide more elaborate designs.

How do I access widget values from other cells in marimo?

After wrapping your widget with `mo.ui.anywidget()`, access its values using `widget.value`, which returns a dictionary containing all synchronized trait values. For example, `widget.value['number']` retrieves the number trait.

What's the proper way to handle state changes between Python and JavaScript?

In JavaScript, use `model.get()` to read values, `model.set()` and `model.save_changes()` to update traits, and `model.on('change:traitname', callback)` to listen for changes. In Python, use `widget.observe(handler)` to react to trait changes following the standard anywidget pattern.

Do I need to include other marimo UI elements in my widget examples?

No. Keep examples minimal and focused on demonstrating the core widget functionality. Only combine with other marimo UI elements if explicitly requested. The goal is to showcase the widget's utility in the simplest way possible.

Install anywidget-generator

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill