A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
More anywidget examples (#7062)
vincent d warmerdam91159cb4f579
diff --git a/docs/api/inputs/anywidget.md b/docs/api/inputs/anywidget.mdindex 4397e9134e..07b222e141 100644--- a/docs/api/inputs/anywidget.md+++ b/docs/api/inputs/anywidget.md@@ -21,6 +21,7 @@ Here is an example using `drawdata`:# pip install drawdatafrom drawdata import ScatterWidget+# Don't forget to wrap the widget with marimo.ui.anywidgetwidget = mo.ui.anywidget(ScatterWidget())# In another cell, you can access the widget's value@@ -32,10 +33,12 @@ widget.data_as_polars```For additional examples, see-[our repo](https://github.com/marimo-team/marimo/tree/main/examples/third_party/anywidget).+[our repo](https://github.com/marimo-team/marimo/tree/main/examples/third_party/anywidget) or our [widgets gallery](https://marimo.io/gallery/widgets).## Custom widget+Anywidget lets you write custom widgets by adding JavaScript to your Python code. Below is an example of a counter widget.+```pythonimport anywidgetimport traitlets@@ -73,6 +76,7 @@ class CounterWidget(anywidget.AnyWidget):"""# Stateful property that can be accessed by JavaScript & Python+count = traitlets.Int(0).tag(sync=True)widget = mo.ui.anywidget(CounterWidget())@@ -84,6 +88,14 @@ widget.value# You can also access the widget's specific propertieswidget.count```+### More examples++If you're eager to build your own widgets and want to dive deeper you may enjoy these resources:++- Before making your own widget, it would be best to check and see if the widget already exists. The [widgets section on the marimo gallery](https://marimo.io/gallery/widgets) as well as the [gallery on anywidget.dev](https://anywidget.dev/en/community/) give you a good overview of what's out there.+- The [wigglystuff repository](https://github.com/koaning/wigglystuff) has many smaller widgets that could serve as an excellent starting point.+- We've noticed that coding agents are getting better at generating these anywidgets on the fly. If you're keen to explore that you can check out our [prompts section](/guides/generate_with_ai/prompts/#anywidget) for a quickstart.+- You may also enjoy [this livestream on the marimo YouTube channel](https://www.youtube.com/watch?v=3V1r5sKnyz8) on building anywidgets.---