1#' Shiny bindings for visNetwork 2#' 3#' Output and render functions for using visNetwork within Shiny 4#' applications and interactive Rmd documents. With \code{visNetworkProxy}, 5#' you can update your network without redraw in shiny. 6#' 7#' @param outputId : output variable to read from 8#' @param width,height Must be a valid CSS unit (like \code{"100\%"}, 9#' \code{"400px"}, \code{"auto"}) or a number, which will be coerced to a 10#' string and have \code{"px"} appended. 11#' @param expr An expression that generates a visNetwork 12#' @param env The environment in which to evaluate \code{expr}. 13#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This 14#' is useful if you want to save an expression in a variable. 15#' @param shinyId single-element character vector indicating the shiny output ID of the 16#' network to modify 17#' @param session the Shiny session object to which the map belongs; usually the 18#' default value will suffice 19#' 20#' @name visNetwork-shiny 21#' 22#' @details 23#' 24#' With \code{visNetworkProxy}, you can update your network and use various methods : 25#' \itemize{ 26#' \item{"all 'visNetwork' functions"}{ : \code{\link{visOptions}}, \code{\link{visNodes}}, \code{\link{visEdges}}, \code{\link{visPhysics}}, \code{\link{visEvents}}, ...} 27#' \item{\code{\link{visFocus}}}{ : Focus to one or more nodes} 28#' \item{\code{\link{visFit}}}{ : Set view on a set of nodes} 29#' \item{\code{\link{visUpdateNodes}}}{ : Update and add nodes} 30#' \item{\code{\link{visUpdateEdges}}}{ : Update and add edges} 31#' \item{\code{\link{visRemoveNodes}}}{ : Remove nodes} 32#' \item{\code{\link{visRemoveEdges}}}{ : Remove edges} 33#' \item{\code{\link{visSelectNodes}}}{ :Select nodes} 34#' \item{\code{\link{visSelectEdges}}}{ : Select edges} 35#' \item{\code{\link{visGetNodes}}}{ : Get nodes dataset} 36#' \item{\code{\link{visGetEdges}}}{ : Get edges dataset} 37#' \item{\code{\link{visSetSelection}}}{ : Select edges/nodes} 38#' \item{\code{\link{visNearestNodes}}}{ : Get nearest nodes} 39#' \item{\code{\link{visCollapse}}}{ : Collapse nodes} 40#' \item{\code{\link{visUncollapse}}}{ : Uncollpase nodes} 41#' \item{\code{\link{visSetTitle}}}{ : Set and update main, submain, footer} 42#' \item{and also...}{ : \code{\link{visGetSelectedEdges}}, \code{\link{visGetSelectedNodes}}, \code{\link{visGetSelection}}, 43#' \code{\link{visGetConnectedEdges}}, \code{\link{visGetConnectedNodes}}, \code{\link{visRedraw}}, \code{\link{visStabilize}}, 44#' \code{\link{visSetData}}, \code{\link{visGetPositions}}, \code{\link{visMoveNode}}, \code{\link{visUnselectAll}}, 45#' \code{\link{visGetScale}}, \code{\link{visGetBoundingBox}}, \code{\link{visGetViewPosition}},\code{\link{visSetOptions}}} 46#'} 47#' 48#' @examples 49#' 50#'\dontrun{ 51#' 52#' # have a look to : 53#' shiny::runApp(system.file("shiny", package = "visNetwork")) 54#' 55#'} 56#' @export 57#' 58#' @references See online documentation \url{http://datastorm-open.github.io/visNetwork/} 59#' 60visNetworkOutput <- function(outputId, width = '100%', height = '400px'){ 61 shinyWidgetOutput(outputId, 'visNetwork', width, height, package = 'visNetwork') 62} 63 64#' @rdname visNetwork-shiny 65#' @export 66renderVisNetwork <- function(expr, env = parent.frame(), quoted = FALSE) { 67 if (!quoted) { expr <- substitute(expr) } # force quoted 68 shinyRenderWidget(expr, visNetworkOutput, env, quoted = TRUE) 69} 70 71 72#' @name visNetwork-shiny 73#' 74#' @export 75visNetworkProxy <- function(shinyId, session = shiny::getDefaultReactiveDomain()){ 76 if (is.null(session)) { 77 stop("visNetworkProxy must be called from the server function of a Shiny app") 78 } 79 80 object <- list(id = shinyId, session = session) 81 class(object) <- "visNetwork_Proxy" 82 object 83} 84