Streamlit-Agraph

0.0.45 · active · verified Thu Apr 16

Streamlit-Agraph is a third-party Streamlit component designed to visualize interactive graph networks directly within Streamlit applications. Built on top of `react-graph-vis`, it provides a Python interface for generating nodes, edges, and customizable graph configurations, including physics, direction, hierarchy, and image support. The current version is 0.0.45, and it appears to be actively maintained with irregular updates, as indicated by recent activity on its GitHub repository. [2, 17]

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple interactive graph in Streamlit using `streamlit-agraph`. It defines a set of nodes and edges, configures the graph's appearance and behavior (e.g., width, height, physics, directed edges), and renders it using the `agraph` component. The `return_value` captures the ID of the last clicked node. [2, 17]

import streamlit as st
from streamlit_agraph import agraph, Node, Edge, Config

nodes = []
edges = []

nodes.append(Node(id="Spiderman", label="Peter Parker", size=25, shape="circularImage", image="http://marvel-force-chart.surge.sh/marvel_force_chart_img/top_spiderman.png"))
nodes.append(Node(id="Captain_Marvel", size=25, shape="circularImage", image="http://marvel-force-chart.surge.sh/marvel_force_chart_img/top_captainmarvel.png"))
nodes.append(Node(id="Iron_Man", label="Tony Stark", size=25, shape="circularImage", image="http://marvel-force-chart.surge.sh/marvel_force_chart_img/top_ironman.png"))

edges.append(Edge(source="Captain_Marvel", label="friend_of", target="Spiderman"))
edges.append(Edge(source="Iron_Man", label="mentor_of", target="Spiderman"))

config = Config(
    width=750,
    height=550,
    directed=True,
    physics=True,
    hierarchical=False,
    # Add a unique key for multiple graphs on a single page
    # key="my_unique_agraph_key"
)

st.title("Streamlit-Agraph Quickstart")
st.markdown("An interactive graph visualization example.")

return_value = agraph(nodes=nodes, edges=edges, config=config)

st.write(f"Node selected: {return_value}")

view raw JSON →