plot_multilayer: Plot a multilayer network in the browser

View source: R/plot_multilayer.R

plot_multilayerR Documentation

Plot a multilayer network in the browser

Description

Converts an EMLN multilayer object to JSON and opens the Multilayer Network Visualizer in the default web browser.

Usage

plot_multilayer(
  multilayer,
  bipartite = FALSE,
  directed = NULL,
  port = 8080,
  viz_path = NULL,
  browser = getOption("browser")
)

Arguments

multilayer

A multilayer object (created by create_multilayer_network or load_emln).

bipartite

Logical. Whether the network is bipartite. Defaults to FALSE. Bipartite is not auto-detected. When TRUE, the nodes table must contain a node_type (or legacy node_group) column with exactly two distinct values across the network.

directed

Logical or NULL. Whether the network is directed. If NULL (default), auto-detected by checking intralayer edge symmetry.

port

Integer. Port for the local HTTP server. Default is 8080.

viz_path

Character. Path to the multilayer_viz directory. If NULL (default), uses the viz directory bundled with the package.

browser

Choose the specific browser to open the visualizer. Defaults to the system default via getOption("browser"). Can be a browser name (e.g. "chrome", "firefox") or a command (e.g. "open -a 'Google Chrome'").

Details

The function:

  1. Converts the multilayer object to JSON via multilayer_to_json

  2. Starts a local HTTP server (using httpuv) that serves the visualizer app and the network JSON

  3. Opens the browser with auto-load enabled

The server runs in the background. Call httpuv::stopServer(handle) or close R to stop it. The JSON data is kept in memory and never written to disk.

Value

Invisibly returns the server handle. Use httpuv::stopServer(handle) to stop the server when done.

Note

The Multilayer Network Visualizer that this function targets is currently in beta. Feedback and bug reports are welcome at https://github.com/Ecological-Complexity-Lab/emln/issues.

See Also

multilayer_to_json, create_multilayer_network, load_emln

Examples

if (interactive()){
net <- load_emln(60)
srv <- plot_multilayer(net, bipartite = TRUE)

# When done:
httpuv::stopServer(srv)
}

emln documentation built on May 6, 2026, 1:06 a.m.