This experiment tests the integration of ObservableHQ exported code into Marimo projects to embed interactive ObservableHQ visualizations in your Marimo notebooks.
The ObservableWidget loads ObservableHQ project files to embed visualizations in a Marimo project. The widget handles file discovery, dependency loading, and data injection.
your-project/
├── example1.py # Marimo notebook
├── example2.py # Marimo notebook
├── observable_widget/ # Widget code
│ └── observable_widget.py
└── dynamic-network-graph/ # ObservableHQ project exported code
└── radical-translations-agents-network-visualisation/ # ObservableHQ project exported code
widget = ObservableWidget(
notebook_path="path-to-observable-project",
json_data={"filename.json": your_data}, # variable containing data to inject to the visualization
visible_cells=["cell1", "cell2"] # cells of the Observable notebook that need displaying
)-
notebook_path (required): Path to the ObservableHQ project directory (exported code).
- Should contain
index.js,runtime.js, and the main notebook files. - Example:
"dynamic-network-graph"
- Should contain
-
json_data (optional): Dictionary mapping data filenames to your data.
- Key: Original filename referenced in the ObservableHQ notebook.
- Value: Your Python data structure (dict, list, etc.).
- Example:
{"treatiesBi@4.json": sample_data}
-
visible_cells (optional): List of cell names to display.
- Only the specified cells will be rendered.
- Useful for showing only specific parts of the visualization.
- Example:
["viewof time", "chart"]
import marimo as mo
from observable_widget import ObservableWidget
# Your data
sample_data = {
"nodes": [
{"id": "A", "start_date": 1450, "end_date": 1784},
{"id": "B", "start_date": 1460, "end_date": 1784}
],
"edges": [
{"source": "A", "target": "B", "start_date": 1460, "end_date": 1784}
]
}
# Create widget
widget = ObservableWidget(
notebook_path="dynamic-network-graph",
json_data={"treatiesBi@4.json": sample_data},
visible_cells=["viewof time", "chart"]
)
# Display in Marimo
widget- Export your ObservableHQ notebook (Download tarball)
- Extract the files to a new directory in your project
- Use the directory name as the
notebook_pathparameter - Map your data to the expected filenames using
json_data
This example includes a visualization created by Dr. Lena Jaskov: https://observablehq.com/@yaslena/dynamic-network-graph. The experiment uses fake data in the Marimo notebook to test the possibility to reuse the visualization with another dataset.
- Clone this repository
- Install dependencies in your python environment:
pip install marimo anywidget - Run the example:
marimo run example1.pyto open the notebook in "app mode" (without code) ormarimo edit example1.pyto show tge editor with UI controls
This example includes a visualization created by Miguel Vieira: https://observablehq.com/@jmiguelv/radical-translations-agents-network-visualisation
- Clone this repository
- Install dependencies in your python environment:
pip install marimo anywidget - Run the example:
marimo run example2.pyto open the notebook in "app mode" (without code) ormarimo edit example2.pyto show tge editor with UI controls