Skip to content

Commit 0555b8c

Browse files
adamnschFlorentinD
authored andcommitted
WIP: Add layout to streamlit example
1 parent 547e535 commit 0555b8c

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()
@@ -37,9 +37,9 @@ def create_visualization_graph() -> VisualizationGraph:
3737

3838
@st.cache_data
3939
def render_graph(
40-
_VG: VisualizationGraph, height: int, initial_zoom: float = 0.1
40+
_VG: VisualizationGraph, height: int, layout: Layout, initial_zoom: float = 0.1
4141
) -> HTML:
42-
return VG.render(initial_zoom=initial_zoom, height=f"{height}px")
42+
return VG.render(initial_zoom=initial_zoom, height=f"{height}px", layout=layout)
4343

4444

4545
VG = create_visualization_graph()
@@ -52,6 +52,10 @@ def render_graph(
5252

5353
with st.sidebar:
5454
height = st.slider("Height in pixels", 100, 2000, 600, 50)
55+
layout = st.radio(
56+
"Layout",
57+
[Layout.FORCE_DIRECTED, Layout.HIERARCHICAL, Layout.GRID],
58+
)
5559
show_code = st.checkbox("Show code")
5660

5761
st.header("Visualization")
@@ -61,7 +65,7 @@ def render_graph(
6165
)
6266

6367
components.html(
64-
render_graph(VG, height=height).data,
68+
render_graph(VG, height=height, layout=layout).data,
6569
height=height,
6670
)
6771

0 commit comments

Comments
 (0)