Skip to main content

Gradio component for displaying vis.js network visualizations.

Project description


tags: [gradio-custom-component, ] title: gradio_networkgraph short_description: Gradio component for displaying vis.js network visualizations. colorFrom: blue colorTo: yellow sdk: gradio pinned: false app_file: space.py

gradio_networkgraph

PyPI - Version

Gradio component for displaying vis.js network visualizations.

Installation

pip install gradio_networkgraph

Usage

import gradio as gr
from gradio_networkgraph import NetworkGraph

OPTIONS = {
    "physics": {
        "stabilization": {
            "enabled": True,
            "fit": True,
            "iterations": 100,
            "onlyDynamicEdges": True,
            "updateInterval": 50,
        },
    }
}


with gr.Blocks() as demo:
    graph_data = gr.State({
        "nodes": [],
        "edges": [],
        "options": OPTIONS
    })
    nodes = gr.State([{'id': 1, "label": "node 1"}, {'id': 2, "label": "node 2"}])
    edges = gr.State([{"from": 1, "to": 2, "label": "edge", "id": "edge1"}])

    def add_node(nodes, edges):
        max_id = max(n["id"] for n in nodes)
        nodes += [{"id": max_id+1, "label": f"Node {max_id + 1}"}]
        edges += [{"from": max_id, "to": max_id + 1}]
        return nodes, edges

    def add_node_to_graph(nodes, edges):
        return {
            "nodes": nodes,
            "edges": edges,
            "options": OPTIONS
        }

    def on_graph_event(graph, event_data: gr.EventData):
        return event_data._data

    graph = NetworkGraph(
        value={
            "nodes": nodes.value,
            "edges": edges.value,
            "options": {}
        },
        label="Static"
    )
    position_output = gr.Textbox(label="Positions:")
    selection_output = gr.Textbox(label="Selection:")
    btn = gr.Button("Add node")
    node_edge_txt = gr.Textbox(
        value=f"Nodes:\n{nodes.value}\n\nEdges:\n{edges.value}",
    )
    graph.selectNode(on_graph_event, inputs=[graph], outputs=[selection_output])
    graph.deselectNode(on_graph_event, inputs=[graph], outputs=[selection_output])
    graph.selectEdge(on_graph_event, inputs=[graph], outputs=[selection_output])
    graph.deselectEdge(on_graph_event, inputs=[graph], outputs=[selection_output])
    graph.stabilizationIterationsDone(on_graph_event, inputs=[graph], outputs=[position_output])
    graph.stabilized(on_graph_event, inputs=[graph], outputs=[position_output])
    btn.click(add_node, inputs=[nodes, edges], outputs=[nodes, edges])
    nodes.change(lambda nodes, edges: f"Nodes:\n{nodes}\n\nEdges:\n{edges}", [nodes, edges], [node_edge_txt])
    nodes.change(add_node_to_graph, [nodes, edges], [graph])


if __name__ == "__main__":
    demo.launch()

NetworkGraph

Initialization

name type default description
value
Any
None None
label
str | None
None None
info
str | None
None None
show_label
bool | None
None None
container
bool
True None
scale
int | None
None None
min_width
int | None
None None
interactive
bool | None
None None
visible
bool
True None
elem_id
str | None
None None
elem_classes
list[str] | str | None
None None
render
bool
True None
key
int | str | None
None None
load_fn
Callable | None
None None
every
Timer | float | None
None None
inputs
Component | Sequence[Component] | set[Component] | None
None None

Events

name description
selectNode
deselectNode
selectEdge
deselectEdge
stabilizationIterationsDone
stabilized

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_networkgraph-0.0.3.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradio_networkgraph-0.0.3-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file gradio_networkgraph-0.0.3.tar.gz.

File metadata

  • Download URL: gradio_networkgraph-0.0.3.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for gradio_networkgraph-0.0.3.tar.gz
Algorithm Hash digest
SHA256 9b49383c41d29c4740cf2ad85ee1ce81435dfb4dce1bc121c47b8f221868f39a
MD5 100ef0b3fdbab88920c3d4e3d7fa0815
BLAKE2b-256 e30c0b374b5aaa3bb773b6d550990c995c45c6ceb2cf06874ae3acbc68e56c05

See more details on using hashes here.

File details

Details for the file gradio_networkgraph-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_networkgraph-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 009b0cff886465c6315ea83c1ae72d018e5c5e2bb519fbe6e23b69bc87482422
MD5 98b3f54a49b00e5022848b231bb03639
BLAKE2b-256 cf6443ee1b39409937297e6bf270dbc7fa0ac8f9fcde4771834e4bd346ce6d6e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page