ipysigma
ipysigma renders a networkx or igraph graph as a GPU-accelerated, clickable network explorer, with search, a clickable legend, and PNG/SVG/GEXF/JSON export built in. @render_ipysigma accepts either a bare graph or a Sigma(...) you construct to control color, size, and labels from attributes or metrics computed in the browser.

Python’s own standard library as an import graph, recolored around a clicked module. Try the app.
Installation
pip install 'shinywidgets[ipysigma]'This installs ipysigma itself. Bring your own graph library – networkx (used throughout this guide) or python-igraph.
Quick start
from __future__ import annotations
import networkx as nx
from shiny.express import ui
from shinywidgets import render_ipysigma
ui.page_opts(title="ipysigma quickstart", fillable=True)
with ui.card(full_screen=True):
ui.card_header("Zachary's karate club (34 members, 78 friendships)")
@render_ipysigma
def graph():
return nx.karate_club_graph()
Returning a bare graph gets you search, zoom controls, a legend placeholder, and export buttons for free. For any visual encoding, construct a Sigma(...) instead, as every other example in this guide does.
Overview
A look at what you can build. Click any of them to open the app, with its code, in Shinylive.
Recolor an import graph around a clicked module
Louvain-colored, PageRank-sized, any networkx graph
20,000 nodes, smooth pan and zoom
Color and size nodes from data attributes
Louvain communities, computed in the browser
Lay out a graph live with ForceAtlas2
Color and size edges by weight
Click a node for a detail card
Two synced views, no Python in the loop
Capture a PNG snapshot on demand
Track camera position and layout convergence
Filter a table from the legend
Sigma()’s full option reference – far more encodings than fit here, including pictograms, halos, and borders – is in ipysigma’s README.
Reacting to interaction
render_ipysigma declares no reactive accessor methods – there’s no graph.selected(). Every interaction instead goes through graph.read("<trait>"), the same way reactive_read(graph.widget, "<trait>") would (see the reacting to widgets article for why). The full trait list is in Reading widget state.
Click for details
@render.ui
def detail():
raw = graph.read("selected_node")
if raw is None:
return ui.p("Click a node to see who they're friends with.")
node = int(raw) # selected_node is always a string
friends = sorted(G.neighbors(node))
return ui.TagList(
ui.h5(f"Member {node}"),
ui.p(f"Club: {G.nodes[node]['club']}"),
ui.p(f"Friends ({len(friends)}): {', '.join(map(str, friends))}"),
)

For an app that combines clicking, a sidebar picker kept in sync both ways, and recoloring around the focus, see the stdlib import graph showcase.
Updating in place
ipysigma reads its constructor options once, when the graph is first drawn, and registers no listeners for later trait changes: setting graph.widget.selected_node = "5" from an effect does reach the browser’s copy of the model (graph.read("selected_node") sees the new value), but nothing changes on screen. There’s no in-place update path here, unlike widgets that mirror trait changes into their view (plotly, itables’ .update()).
The practical pattern is to re-render, carrying forward whatever state you don’t want to lose – typically camera_state (and layout, if a layout has already converged) – by mirroring it into a reactive.value with an effect, then feeding it back into the next Sigma(...):
camera = reactive.value({"x": 0.5, "y": 0.5, "ratio": 1, "angle": 0})
@reactive.effect
def _track_camera():
req(graph.widget)
camera.set(graph.read("camera_state"))
@render_ipysigma
def graph():
color_by = input.color_by()
with reactive.isolate():
# isolate(): reading .widget here (not just camera) would create a
# circular dependency on this render's own previous output
cam = camera.get()
if color_by == "club":
return Sigma(G, node_color="club", camera_state=cam)
return Sigma(
G,
node_color=dict(G.degree()),
node_color_gradient=("#dbe9f6", "#08306b"),
camera_state=cam,
)Switching color schemes rebuilds the graph entirely, but the zoomed-in view from before the switch is preserved exactly:


Don’t read graph.widget inside graph() itself without reactive.isolate() – before the first render, that raises req(False) and cancels the output silently. Mirroring into a reactive.value via a separate effect (as above) sidesteps this.
Linking widgets
Click to filter a table
Same read as the detail card above, different downstream view – a selected node’s neighbors as a data frame instead of prose.
@render.data_frame
def neighbor_table():
raw = graph.read("selected_node")
req(raw)
neighbors = sorted(G.neighbors(int(raw)))
return members[members["member"].isin(neighbors)].reset_index(drop=True)

Two synced views
Give two Sigmas the same sync_key and the browser keeps their camera, selection, and hover in sync directly – each still reports its own selected_node to Python, so both update together with no effect wiring at all. This is the Shiny replacement for ipysigma’s SigmaGrid (a Jupyter-only small-multiples helper that isn’t a widget and can’t be returned from a render function).
with ui.layout_columns(col_widths=[6, 6]):
with ui.card(full_screen=True):
ui.card_header("By club")
@render_ipysigma
def by_club():
# sync_key links pan/zoom/selection/hover between every Sigma that
# shares it, even across separate outputs
return Sigma(G, node_color="club", sync_key="karate")
with ui.card(full_screen=True):
ui.card_header("By friend count")
@render_ipysigma
def by_degree():
return Sigma(
G,
node_color=dict(G.degree()),
node_color_gradient=("#dbe9f6", "#08306b"),
sync_key="karate",
)Clicking node 33 in the left graph selects it in both, including the right graph’s detail panel:


Legend click filters a table
selected_node_category_values isn’t just for dimming the graph – read it anywhere a category filter is useful.
@render.data_frame
def visible():
# [] (nothing filtered) means "show everything", not "show nothing"
categories = graph.read("selected_node_category_values")
shown = members if not categories else members[members["club"].isin(categories)]
return shown.reset_index(drop=True)

Reading widget state
| Trait | returns | fires when | None/[] means |
default rate policy |
|---|---|---|---|---|
selected_node |
str \| None |
clicking a node, choosing one in the search box, or in-graph search | nothing selected (also clears when an edge or stage is clicked) | not rate-limited |
selected_edge |
(str, str) \| None |
clicking an edge (requires clickable_edges=True) |
nothing selected (also clears when a node is clicked) | not rate-limited |
selected_node_category_values |
list \| None |
clicking a swatch in the legend | []/None: no filter, every category shown |
not rate-limited |
camera_state |
dict (x, y, ratio, angle) |
panning or zooming | n/a – always has a value | not rate-limited |
layout |
dict[node, {"x", "y"}] \| None |
once at mount, and again whenever ForceAtlas2 (start_layout) stops |
None until the first layout exists |
not rate-limited |
snapshot |
str (PNG data URL) \| None |
after you send {"msg": "render_snapshot"} (there’s no browser gesture for it) |
no snapshot captured yet | not rate-limited |
selected_node is always a str, even for integer node keys – int(graph.read("selected_node")) converts it back, or call graph.widget.get_selected_node(), which returns the original key type (only after a .read() on the same widget has already established the reactive dependency, since get_selected_node() doesn’t take one itself). graph.widget.trait_names() lists many more traits, mostly write-only rendering options you pass to Sigma() at construction instead.
Node, edge, and legend selection
Node and edge selection are mutually exclusive (selecting one clears the other); the legend’s category filter is independent of both and persists across node/edge clicks.
@render.code
def state():
node = graph.read("selected_node")
edge = graph.read("selected_edge")
categories = graph.read("selected_node_category_values")
return (
f"selected_node: {node!r}\n"
f"selected_edge: {edge!r}\n"
f"selected_node_category_values: {categories!r}"
)Before any interaction, and after clicking a legend swatch (filtering to one community) and then an edge (which clears the node selection but keeps the filter):


camera_state and layout
Panning, zooming, and a running start_layout all write back reactively. Positions in layout are keyed by node and already match the coordinate space you’d pass back into a new Sigma(..., layout=...).
@render.code
def state():
camera = graph.read("camera_state")
layout = graph.read("layout")
n_positioned = 0 if layout is None else len(layout)
camera_lines = "\n".join(f" {k}: {v:.3g}" for k, v in camera.items())
return f"camera_state:\n{camera_lines}\nlayout: {n_positioned} node positions"Before any interaction, and after panning, zooming, and letting start_layout finish:


Snapshot
ipysigma accepts exactly one command from Python: sending {"msg": "render_snapshot"} makes the browser render a PNG and write it to the snapshot trait as a data URL, which .read("snapshot") picks up like any other trait change.
@reactive.effect
@reactive.event(input.snap)
def _request_snapshot():
# The only Python -> browser command ipysigma exposes: it answers
# by setting the `snapshot` trait to a PNG data URL.
graph.widget.send({"msg": "render_snapshot"})
@render.ui
def png():
data_url = graph.read("snapshot")
if data_url is None:
return ui.p("No snapshot yet -- click the button.")
return ui.img(src=data_url, style="max-width: 100%;")Before capturing, and after clicking “Capture PNG”:


Rate limiting
rate_policy/rate_delay on @render_ipysigma rate-limit .read()/reactive_read() for every trait on that widget, not one at a time. A normal pan or zoom rarely needs it – ipysigma’s own camera updates are already infrequent. It matters when something produces a rapid burst of changes, or when the computation a read triggers is expensive enough that even ipysigma’s own pace is too frequent.
with ui.layout_columns(col_widths=[6, 6]):
with ui.card(full_screen=True):
ui.card_header("Drag me -- not rate-limited")
@render_ipysigma
def unthrottled():
return Sigma(G, sync_key="cam")
with ui.card(full_screen=True):
ui.card_header("Same camera, throttled to 1 read per 2 seconds")
@render_ipysigma(rate_policy="throttle", rate_delay=2)
def throttled():
return Sigma(G, sync_key="cam")A normal drag rarely changes the camera fast enough to show the difference, so these screenshots drive a rapid burst of camera_state changes directly on the model, mirrored to both widgets by sync_key. The unthrottled counter keeps pace; the throttled one, capped to one read per 2 seconds, falls behind during the burst and catches up once it settles:


Large data
ipysigma draws with the GPU (sigma.js/WebGL), the “draw it with the GPU in the browser” approach – see Large data & performance’s three approaches. Passing precomputed layout= positions (rather than letting ipysigma lay the graph out) avoids both the random-hairball first frame and a full position write-back to Python on first render:
@render_ipysigma
def graph():
return Sigma(
G,
layout=layout,
node_color="cluster",
default_node_size=2,
hide_edges_on_move=True, # keeps panning smooth at this size
)
20,000 nodes and their edges pan and zoom smoothly at this size. The legend caps categorical colors at 10 by default (max_categorical_colors); clusters beyond that render gray, which is worth knowing before you wonder where your colors went.
Past this scale, ipycytoscape – the sibling that renders one ipywidget per element – is the one that falls over first, not this renderer.
Layout and sizing
In a filling layout, the graph fills its container – unless the widget has an explicit height/raw_height (a height of 500px, sigma’s default, or one set globally with Sigma.set_defaults(height=...), still counts as “unset” and fills). output_widget(..., fillable=False) – a container with no definite height – falls back to sigma’s 500px default rather than collapsing to 0.
full_screen=True cards and ipysigma’s own fullscreen button both work and restore the prior size on exit. The 250px info/legend panel eats into a narrow card’s width – pass hide_info_panel=True if you’re embedding a small graph. The info panel can also visually overlap the canvas in a narrow container (it’s absolutely positioned on top), which only matters if you’re scripting clicks against it, not for normal use.
Gotchas
- Setting a trait such as
graph.widget.selected_nodeor.camera_statefrom Python doesn’t change anything on screen. Re-render instead (see Updating in place). - Node keys must be
int,str, orfloat, and not mixed. Seeselected_nodeabove for the string round-trip. SigmaGridisn’t supported: it’s a Jupyter-only display helper, not a widget, so it can’t be returned from@render_ipysigma. Use two outputs sharing async_keyinstead (see Linking widgets).
In the gallery
Complete apps in the gallery that use ipysigma:
Learn more
- ipysigma on GitHub – the full
Sigma()option reference - sigma.js – the underlying WebGL rendering library
- graphology – the underlying graph data structure library
- ipycytoscape – smaller graphs, richer styling
- itables – a richer table for the linked-view patterns above
- reactable – a richer table for the linked-view patterns above