Skip to content

Commit 47cd835

Browse files
committed
Setup marimo example
1 parent 0b831d4 commit 47cd835

8 files changed

Lines changed: 3386 additions & 2927 deletions

File tree

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.ipynb_checkpoints
22

33
out/*
4+
/__marimo__/session/*

examples/marimo-example.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# type: ignore
2+
3+
import marimo
4+
5+
__generated_with = "0.20.2"
6+
app = marimo.App(width="full", app_title="Neo4jVizExample")
7+
8+
9+
@app.cell
10+
def _():
11+
import marimo as mo
12+
13+
return (mo,)
14+
15+
16+
@app.cell(hide_code=True)
17+
def _(mo):
18+
mo.md(r"""
19+
# Neo4j Graph Visualization with Marimo
20+
21+
This example demonstrates how to use `neo4j-viz` to visualize graphs in Marimo notebooks.
22+
We'll create a simple graph representing a social network with people and their relationships.
23+
""")
24+
return
25+
26+
27+
@app.cell
28+
def _():
29+
from neo4j_viz import Node, Relationship, VisualizationGraph
30+
31+
return Node, Relationship, VisualizationGraph
32+
33+
34+
@app.cell(hide_code=True)
35+
def _(mo):
36+
mo.md(r"""
37+
## Create Nodes and Relationships
38+
""")
39+
return
40+
41+
42+
@app.cell
43+
def _(Node, Relationship):
44+
# Create nodes representing people
45+
nodes = [
46+
Node(id=0, size=10, caption="Person", properties={"age": 25}),
47+
Node(id=1, size=10, caption="Product", properties={"price": 100}),
48+
Node(id=2, size=20, caption="Product", properties={"price": 200}),
49+
Node(id=3, size=10, caption="Person", properties={"age": 30}),
50+
Node(id=4, size=10, caption="Product"),
51+
]
52+
relationships = [
53+
Relationship(source=0, target=1, caption="BUYS"),
54+
Relationship(source=0, target=2, caption="BUYS"),
55+
Relationship(source=3, target=2, caption="BUYS"),
56+
]
57+
return nodes, relationships
58+
59+
60+
@app.cell(hide_code=True)
61+
def _(mo):
62+
mo.md(r"""
63+
## Visualize the Graph as a Widget
64+
""")
65+
return
66+
67+
68+
@app.cell
69+
def _(VisualizationGraph, nodes, relationships):
70+
# Create and render the visualization
71+
VG = VisualizationGraph(nodes=nodes, relationships=relationships)
72+
widget = VG.render_widget(theme="light", renderer="canvas")
73+
widget
74+
return VG, widget
75+
76+
77+
@app.cell
78+
def _(widget):
79+
print(widget.theme)
80+
print(widget.options)
81+
return
82+
83+
84+
@app.cell
85+
def _(Node, Relationship, widget):
86+
# Run this cell multiple times - each run adds a new node to the widget above
87+
import random
88+
89+
new_id = len(widget.nodes)
90+
target_id = random.choice([n["id"] for n in widget.nodes])
91+
92+
new_node = Node(id=new_id, size=10, caption="Person")
93+
new_rel = Relationship(source=new_id, target=target_id, caption="KNOWS")
94+
95+
widget.add_data(nodes=[new_node], relationships=[new_rel])
96+
return
97+
98+
99+
@app.cell(hide_code=True)
100+
def _(mo):
101+
mo.md(r"""
102+
## Standalone Visualization the Graph
103+
""")
104+
return
105+
106+
107+
@app.cell
108+
def _(VG):
109+
import os
110+
111+
VG.render()
112+
return
113+
114+
115+
if __name__ == "__main__":
116+
app.run()

justfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
root_dir := justfile_directory()
2+
py_dir := root_dir / 'python-wrapper'
3+
14
py-sync:
25
cd python-wrapper && uv sync --group dev --group docs --group notebook --extra pandas --extra neo4j --extra gds --extra snowflake
36

@@ -46,6 +49,16 @@ js-build:
4649
streamlit:
4750
./scripts/run_streamlit_example.sh
4851

52+
marimo:
53+
#!/usr/bin/env bash
54+
set -e
55+
cd {{py_dir}} && uv run --group notebook marimo run {{root_dir}}/examples/marimo-example.py
56+
57+
marimo-edit:
58+
#!/usr/bin/env bash
59+
set -e
60+
cd {{py_dir}} && uv run --group notebook marimo edit {{root_dir}}/examples/marimo-example.py
61+
4962
ref-docs:
5063
./scripts/render_antora_docs.sh
5164

python-wrapper/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ notebook = [
7878
"snowflake-snowpark-python==1.42.0",
7979
"dotenv",
8080
"requests",
81+
"marimo",
8182
]
8283

8384
[project.urls]
@@ -173,3 +174,6 @@ exclude = [
173174
]
174175
plugins = ['pydantic.mypy']
175176
untyped_calls_exclude=["nbconvert"]
177+
178+
[tool.marimo.runtime]
179+
output_max_bytes = 20_000_000

python-wrapper/src/neo4j_viz/resources/nvl_entrypoint/index.html

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.

python-wrapper/src/neo4j_viz/resources/nvl_entrypoint/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)