Skip to content

Commit 08fe9fd

Browse files
committed
WIP: Add layout to streamlit example
1 parent 70d4c0a commit 08fe9fd

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

examples/streamlit-example.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pathlib
66

77
from neo4j_viz.pandas import from_dfs
8-
from neo4j_viz import VisualizationGraph
8+
from neo4j_viz import VisualizationGraph, Layout
99

1010
# Path to this file
1111
script_path = pathlib.Path(__file__).resolve()
@@ -32,9 +32,9 @@ def create_visualization_graph() -> VisualizationGraph:
3232

3333
@st.cache_data
3434
def render_graph(
35-
_VG: VisualizationGraph, height: int, initial_zoom: float = 0.1
35+
_VG: VisualizationGraph, height: int, layout: Layout, initial_zoom: float = 0.1
3636
) -> HTML:
37-
return VG.render(initial_zoom=initial_zoom, height=f"{height}px")
37+
return VG.render(initial_zoom=initial_zoom, height=f"{height}px", layout=layout)
3838

3939

4040
VG = create_visualization_graph()
@@ -47,6 +47,10 @@ def render_graph(
4747

4848
with st.sidebar:
4949
height = st.slider("Height in pixels", 100, 2000, 600, 50)
50+
layout = st.radio(
51+
"Layout",
52+
[Layout.FORCE_DIRECTED, Layout.HIERARCHICAL, Layout.GRID],
53+
)
5054
show_code = st.checkbox("Show code")
5155

5256
st.header("Visualization")
@@ -56,7 +60,7 @@ def render_graph(
5660
)
5761

5862
components.html(
59-
render_graph(VG, height=height).data,
63+
render_graph(VG, height=height, layout=layout).data,
6064
height=height,
6165
)
6266

0 commit comments

Comments
 (0)