Title: | Cytoscape.js Shiny Widget (cyjShiny) |
---|---|
Description: | Wraps cytoscape.js as a shiny widget. cytoscape.js <https://js.cytoscape.org/> is a Javascript-based graph theory (network) library for visualization and analysis. This package supports the visualization of networks with custom visual styles and several available layouts. Demo Shiny applications are provided in the package code. |
Authors: | Omar Shah [ctb], Paul Shannon [aut], Augustin Luna [aut, cre] |
Maintainer: | Augustin Luna <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.42 |
Built: | 2024-12-07 06:51:37 UTC |
Source: | CRAN |
Add graph from data.frame
addGraphFromDataFrame(session, tbl.edges, tbl.nodes = NULL)
addGraphFromDataFrame(session, tbl.edges, tbl.nodes = NULL)
session |
a Shiny Server session object. |
tbl.edges |
a data.frame with source, traget, interaction columns (and option other attributes) |
tbl.nodes |
(optional; nodes can be deduced from tbl.edges) a data.frame with nodes and their attributes |
Nothing
## Not run: addGraphFromDataFrame(session) ## End(Not run)
## Not run: addGraphFromDataFrame(session) ## End(Not run)
Add graph from JSON file
addGraphFromJsonFile(session, jsonFilename)
addGraphFromJsonFile(session, jsonFilename)
session |
a Shiny Server session object. |
jsonFilename |
of a text file with JSON representation of a cytoscape.js graph |
Nothing
## Not run: addGraphFromJsonFile(session) ## End(Not run)
## Not run: addGraphFromJsonFile(session) ## End(Not run)
Clear selection all node and edge selections removed
clearSelection(session)
clearSelection(session)
session |
a Shiny Server session object. |
Nothing
This widget wraps cytoscape.js, a full-featured Javsscript network library for visualization and analysis.
cyjShiny( graph, layoutName, styleFile = NULL, width = NULL, height = NULL, elementId = NULL )
cyjShiny( graph, layoutName, styleFile = NULL, width = NULL, height = NULL, elementId = NULL )
graph |
a graph in json format; converters from graphNEL and data.frame/s offered ("see also" below) |
layoutName |
character one of:"preset", "cose", "cola", "circle", "concentric", "breadthfirst", "grid", "random" |
styleFile |
default NULL, can name a standard javascript cytoscape.js style file |
width |
integer initial width of the widget. |
height |
integer initial height of the widget. |
elementId |
string the DOM id into which the widget is rendered, default NULL is best. |
a reference to an htmlwidget.
tbl.nodes <- data.frame( id = c("A", "B", "C"), type = c("kinase", "TF", "glycoprotein"), lfc = c(-3, 1, 1), count = c(0, 0, 0), stringsAsFactors = FALSE ) tbl.edges <- data.frame( source = c("A", "B", "C"), target = c("B", "C", "A"), interaction = c("phosphorylates", "synthetic lethal", "unknown"), stringsAsFactors = FALSE ) # simple legitimate graph, nodes implied, but no node attributes graph.json.v1 <- dataFramesToJSON(tbl.edges) # nodes and edges both explicit, attributes specified graph.json.v2 <- dataFramesToJSON(tbl.edges, tbl.nodes) g <- graphNEL(nodes = c("A", "B", "C"), edgemode = "directed") g <- addEdge("A", "B", g) graph.json.v3 <- graphNELtoJSON(g) # output$cyjShiny <- renderCyjShiny(cyjShiny(graph.json.v[123]))
tbl.nodes <- data.frame( id = c("A", "B", "C"), type = c("kinase", "TF", "glycoprotein"), lfc = c(-3, 1, 1), count = c(0, 0, 0), stringsAsFactors = FALSE ) tbl.edges <- data.frame( source = c("A", "B", "C"), target = c("B", "C", "A"), interaction = c("phosphorylates", "synthetic lethal", "unknown"), stringsAsFactors = FALSE ) # simple legitimate graph, nodes implied, but no node attributes graph.json.v1 <- dataFramesToJSON(tbl.edges) # nodes and edges both explicit, attributes specified graph.json.v2 <- dataFramesToJSON(tbl.edges, tbl.nodes) g <- graphNEL(nodes = c("A", "B", "C"), edgemode = "directed") g <- addEdge("A", "B", g) graph.json.v3 <- graphNELtoJSON(g) # output$cyjShiny <- renderCyjShiny(cyjShiny(graph.json.v[123]))
Standard shiny ui rendering construct
cyjShinyOutput(outputId, width = "100%", height = "400")
cyjShinyOutput(outputId, width = "100%", height = "400")
outputId |
the name of the DOM element to create. |
width |
integer optional initial width of the widget. |
height |
integer optional initial height of the widget. |
a reference to an htmlwidget
## Not run: mainPanel(cyjShinyOutput("cyjShiny"), width = 10) ## End(Not run)
## Not run: mainPanel(cyjShinyOutput("cyjShiny"), width = 10) ## End(Not run)
Create a cytoscape.js JSON graph from one or two data.frames.
dataFramesToJSON(tbl.edges, tbl.nodes = NULL)
dataFramesToJSON(tbl.edges, tbl.nodes = NULL)
tbl.edges |
data.frame, with source, target and interaction columns, others option for edge attributes |
tbl.nodes |
data.frame, options, useful for orphan nodes, and necessary for adding node attributes |
a string with a cytoscape.js JSON graph
Layout the current graph using the specified strategy.
doLayout(session, strategy)
doLayout(session, strategy)
session |
a Shiny Server session object. |
strategy |
a character string, one of cola, cose, circle, concentric, grid, breadthfirst, random, dagre, cose-bilkent. |
Nothing
## Not run: doLayout(session, "cola") ## End(Not run)
## Not run: doLayout(session, "cola") ## End(Not run)
Set zoom and center of the graph display so that graph fills the display.
fit(session, padding = 50)
fit(session, padding = 50)
session |
a Shiny server session object. |
padding |
integer, default 50 pixels. |
Nothing
## Not run: fit(session, 100) ## End(Not run)
## Not run: fit(session, 100) ## End(Not run)
Set zoom and center of the graph display so that the currently selected nodes fill the display
fitSelected(session, padding = 50)
fitSelected(session, padding = 50)
session |
a Shiny server session object. |
padding |
integer, default 50 pixels. |
Nothing
## Not run: fitSelected(session, 100) ## End(Not run)
## Not run: fitSelected(session, 100) ## End(Not run)
Get node positions
getNodePositions(session)
getNodePositions(session)
session |
a Shiny Server session object. |
Nothing
Get Selected Nodes
getSelectedNodes(session)
getSelectedNodes(session)
session |
a Shiny server session object. |
a data.frame with (at least) an id column
getSelectedNodes
get the selected nodes
Convert R graphNEL object to cytoscape.js JSON.
graphNELtoJSON(g)
graphNELtoJSON(g)
g |
a graphNEL |
a string with a cytoscape.js JSON graph
## Not run: g.json <- graphNELtoJSON(graphNEL()) ## End(Not run)
## Not run: g.json <- graphNELtoJSON(graphNEL()) ## End(Not run)
Hide selection all selected nodes and their edges are hidden
hideSelection(session)
hideSelection(session)
session |
a Shiny Server session object. |
Nothing
Invert selection all selected nodes and their edges are hidden
invertSelection(session)
invertSelection(session)
session |
a Shiny Server session object. |
Nothing
Load a standard cytoscape.js JSON network file
loadNetworkFromJSONFile(filename)
loadNetworkFromJSONFile(filename)
filename |
character string, either relative or absolute path. |
Nothing
## Not run: loadNetworkFromJSONFile(system.file(package = "cyjShiny", "extdata", "galFiltered.cyjs")) ## End(Not run)
## Not run: loadNetworkFromJSONFile(system.file(package = "cyjShiny", "extdata", "galFiltered.cyjs")) ## End(Not run)
Load a standard cytoscape.js style file
loadStyleFile(styleFile)
loadStyleFile(styleFile)
styleFile |
character string, either relative or absolute path. |
Nothing
## Not run: loadStyleFile(system.file(package = "cyjShiny", "extdata", "yeastGalactoseStyle.js")) ## End(Not run)
## Not run: loadStyleFile(system.file(package = "cyjShiny", "extdata", "yeastGalactoseStyle.js")) ## End(Not run)
Read in a JSON network file, identify (or add) elements field return JSON
readAndStandardizeJSONNetworkFile(filename)
readAndStandardizeJSONNetworkFile(filename)
filename |
a JSON file |
a string with a cytoscape.js JSON graph
this utility function examines the incoming JSON, returns exactly and only an array of selector objects
readAndStandardizeJSONStyleFile(filename)
readAndStandardizeJSONStyleFile(filename)
filename |
a json file |
there are at least two JSON object structures used to specify style (see function comments in code for more details):
simple: an array of selector objects
more complex, exported from the Cytoscape desktop application this is also an array of objects, one named "style" which (like the simple format described above) contains an array of selectors.
a string with a cytoscape.js JSON graph
Remove the current graph
removeGraph(session)
removeGraph(session)
session |
a Shiny Server session object. |
Nothing
## Not run: removeGraph(session) ## End(Not run)
## Not run: removeGraph(session) ## End(Not run)
More shiny plumbing - a cyjShiny wrapper for htmlwidget standard rendering operation
renderCyjShiny(expr, env = parent.frame(), quoted = FALSE)
renderCyjShiny(expr, env = parent.frame(), quoted = FALSE)
expr |
an expression that generates an HTML widget. |
env |
environment in which to evaluate expr. |
quoted |
logical specifies whether expr is quoted ("useuful if you want to save an expression in a variable"). |
output from htmlwidgets rendering operation
Save a png rendering of the current network view to the specified filename
savePNGtoFile(session, filename)
savePNGtoFile(session, filename)
session |
a Shiny Server session object. |
filename |
a character string |
Nothing
Select first neighbors of the currently selected nodes
selectFirstNeighbors(session)
selectFirstNeighbors(session)
session |
a Shiny Server session object. |
Nothing
Select Nodes
selectNodes(session, nodeNames)
selectNodes(session, nodeNames)
session |
a Shiny Server session object. |
nodeNames |
character, a list of node IDs |
Nothing
Assign the supplied edge attribute values to the graph structure contained in the browser.
setEdgeAttributes( session, attributeName, sourceNodes, targetNodes, interactions, values )
setEdgeAttributes( session, attributeName, sourceNodes, targetNodes, interactions, values )
session |
a Shiny Server session object. |
attributeName |
character string, the attribute to update. |
sourceNodes |
a character vector, the names of the source nodes of the edges |
targetNodes |
a character vector, the names of the target nodes of the edgees |
interactions |
a character vector, further identifying the specific edge whose attributes are updated. |
values |
a character, logical or numeric vector, the new values. |
Nothing
## Not run: setEdgeAttributes(session, attributeName = "score", sourceNodes = c("A", "B", "C"), targetNodes = c("D", "E", "A"), interactions = c("promotes", "promotes", "inhibits"), values = new.scores ) ## End(Not run)
## Not run: setEdgeAttributes(session, attributeName = "score", sourceNodes = c("A", "B", "C"), targetNodes = c("D", "E", "A"), interactions = c("promotes", "promotes", "inhibits"), values = new.scores ) ## End(Not run)
Assign the supplied node attribute values to the graph structure contained in the browser.
setNodeAttributes(session, attributeName, nodes, values)
setNodeAttributes(session, attributeName, nodes, values)
session |
a Shiny Server session object. |
attributeName |
character string, the attribute to update. |
nodes |
a character vector the names of the nodes whose attributes are updated. |
values |
a character, logical or numeric vector, the new values. |
Nothing
## Not run: setNodeAttributes(session, attributeName = attribute, nodes = yeastGalactodeNodeIDs, values = expression.vector ) ## End(Not run)
## Not run: setNodeAttributes(session, attributeName = attribute, nodes = yeastGalactodeNodeIDs, values = expression.vector ) ## End(Not run)
Set node positions from the supplied data.frame
setNodePositions(session, tbl.positions)
setNodePositions(session, tbl.positions)
session |
a Shiny Server session object. |
tbl.positions |
a data.frame with three columns: id, x, y |
Nothing
Show all all selected nodes and their edges are hidden
showAll(session)
showAll(session)
session |
a Shiny Server session object. |
Nothing