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_interaction(graph, event_data: gr.EventData):
        return event_data._data

    graph = NetworkGraph(
        value={
            "nodes": nodes.value,
            "edges": edges.value,
            "options": {}
        },
        label="Static"
    )
    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_interaction, inputs=[graph], outputs=[output])
    graph.deselectNode(on_graph_interaction, inputs=[graph], outputs=[output])
    graph.selectEdge(on_graph_interaction, inputs=[graph], outputs=[output])
    graph.deselectEdge(on_graph_interaction, inputs=[graph], outputs=[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
afterDrawing
stabilizationStep

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.2.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.2-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gradio_networkgraph-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 69b5ac65a6ed0199bd1e2ec9601fd262f7ef956011f42aa6078ecad924d762c9
MD5 348ad3874f54a25d795dd06b94b77e00
BLAKE2b-256 f5cf7a9c6a34d3667064b72703261dca1ea4dac7f47a8bbd13859f67bd7ed2b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gradio_networkgraph-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bf54623b8b13ef269dcf542d5e5a7da117278eb10203ec702072a55b75393162
MD5 7d3211bc56541a54f5961a691e89c731
BLAKE2b-256 6eaee59bc7aec9bf8c50028ff18e21276bac7b89918effc4974af3be8b719c62

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