Display a GEXF encoded network graph
is a R-wrapper for the sigma javascript library of graph drawing. Data should be in GEXF encoded file.
@param gexf the GEXF encoded data @param drawEdges Logical, whether or not to display the edges of the graph @param drawNodes Logical, whether or not to display the nodes of the graph @param width the width of the container @param height the height of the container @param … other arguments passed to specific methods @return a sigmajs object @import htmlwidgets @export @seealso
sigma <- function(gexf, drawEdges = TRUE, drawNodes = TRUE, dragNodes = TRUE,
width = NULL, height = NULL) {
# read the gexf file
data <- paste(readLines(gexf), collapse="\n")
# create a list that contains the settings
settings <- list(
drawEdges = drawEdges,
drawNodes = drawNodes,
dragNodes = dragNodes
)
# pass the data and settings using 'x'
x <- list(
data = data,
settings = settings
)
# create the widget
htmlwidgets::createWidget("sigma", x, width = width, height = height)
}
@export
sigmaOutput <- function(outputId, width = "100%", height = "400px") {
htmlwidgets::shinyWidgetOutput(outputId, "sigma", width, height, package = "sigma")
}
@export
renderSigma <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, sigmaOutput, env, quoted = TRUE)
}