anywidget-generator

Generate anywidget components with vanilla JavaScript and CSS for marimo notebooks.

465|41|Updated Aug 4, 2026
One-click install
npx skills add https://github.com/autonomous-ai/openharness --skill anywidget-generator-autonomous-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: anywidget-generator
Source: https://github.com/autonomous-ai/openharness/tree/main/store/agents/marimo/skills/anywidget
Command: npx skills add https://github.com/autonomous-ai/openharness --skill anywidget-generator-autonomous-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires anywidget, traitlets, marimo.

What problem does it solve? Building interactive widgets for marimo notebooks requires correctly wiring Python traits to JavaScript rendering logic, and small mistakes in the _esm module or missing _css styling produce broken or unstyled widgets. ## Core Features & Use Cases - Widget Scaffolding: Produces anywidget classes with a proper render({ model, el }) function, trait synchronization via model.get/model.set/model.save_changes, and the required default export. - Styling Guidance: Adds minimal bespoke _css that works in both light and dark mode using @media (prefers-color-scheme: dark). - Marimo Integration: Wraps widgets with mo.ui.anywidget(...) so values are accessible as a dictionary via widget.value, and supports external _esm/_css files through pathlib for larger widgets. - Use Case: Ask for an interactive counter or color picker widget and receive a ready-to-run marimo cell with the widget class, styling, and display wrapper. ## Quick Start Ask the agent to create an anywidget for marimo, for example a counter widget with a button that increments a synced number trait.

Frequently Asked Questions about anywidget-generator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a custom widget in a marimo notebook?

Create a class inheriting from anywidget.AnyWidget with an _esm string containing a render function and synced traitlets, then display it with mo.ui.anywidget(YourWidget()). Access its state through widget.value, which returns a dictionary of trait values.

How do I sync state between Python and JavaScript in anywidget?

Define traits with traitlets and tag them with sync=True. In JavaScript, read values with model.get(), update them with model.set() followed by model.save_changes(), and react to changes with model.on("change:traitname", callback).

Can anywidget use external JavaScript and CSS files?

Yes, point _esm and _css to external files using pathlib, typically with paths relative to Path(__file__). This is recommended when the widget contains elaborate JavaScript or CSS that would clutter the Python file.

How do I style an anywidget for dark mode?

Include a _css string on the widget class and use the media query @media (prefers-color-scheme: dark) to override colors for dark mode. Keep the CSS minimal and bespoke so it looks intentional in both light and dark themes.

Why is my anywidget not rendering in marimo?

Common causes are missing the default export of the render function in _esm, forgetting to wrap the widget with mo.ui.anywidget(), or not tagging traits with sync=True. Check that the module ends with export default { render }.