writeHTML: Save network visualization as HTML file

View source: R/Visualize.R

writeHTMLR Documentation

Save network visualization as HTML file

Description

Save an interactive single page visualization of RCX and CX networks as an HTML file containing all necessary Java Script.

Usage

writeHTML(x, file, layout = NULL, verbose = FALSE)

## S3 method for class 'RCX'
writeHTML(x, file, layout = NULL, verbose = FALSE)

## S3 method for class 'CX'
writeHTML(x, file, layout = NULL, verbose = FALSE)

Arguments

x

network; RCX or CX object

file

character; path, where the html file should be saved

layout

named character or list; e.g. c(name="random")

verbose

logical; whether to print what is happening

Details

This function uses the Java Script library used by the NDEx platform (https://ndexbio.org/) to visualize the RCX or CX network. The RCX is therefore converted to CX (JSON) using toCX.

If the network contains the necessary Cytoscape styles (see http://manual.cytoscape.org/en/stable/Styles.html) the network is visualized as seen on the NDEx platform.

To define the layout of the network the coordinate from CartesianLayout are used to determine the location of the nodes. If this aspect is missing, or the the coordinates should be ignored, the layout parameter can be used to set a different layout.

layout follows therefore the definition of Cytoscape.js (see https://js.cytoscape.org/#layouts). A simple definition can be setting only the name of the desired layout, e.g. random. Additional options can be passed as named list, where the values are passed without quoting. This allows for even passing Java Script functions to Cytoscape.js.

To visualize the network in RStudio the visualize function can be used instead.

Value

file character; path, where the html file has been saved

See Also

rcxToJson, readCX, writeCX

Examples

## prepare RCX
rcx = createRCX(
  createNodes(name = c("a","b","c")), 
  createEdges(
    source=c(0,0,1), 
    target=c(1,2,2)
  )
)

cx = toCX(rcx)

htmlFile = tempfile(fileext = ".html")

## save the html
writeHTML(rcx, htmlFile)

## or
writeHTML(cx, htmlFile)

## force a different layout
writeHTML(rcx, htmlFile, c(name="cose"))

## force a different layout with Java Script parameters
writeHTML(rcx, htmlFile, layout = c(name="random",animate="true"))

## even pass a Java Script function
writeHTML(
   rcx, 
   htmlFile, 
   layout = c(
     name="random",
     animate="true",
     animateFilter="function ( node, i ){ return true; }"
   )
)

frankkramer-lab/RCX documentation built on Feb. 4, 2023, 5:12 p.m.