1#' Function to select edge(s) / node(s) from network, with shiny only.
2#'
3#' Function to select edge(s) / node(s) from network, with shiny only.
4#'
5#'@param graph : a \code{\link{visNetworkProxy}}  object
6#'@param nodesId : vector of id, nodes(s) to select
7#'@param edgesId : vector of id, edges(s) to select
8#'@param unselectAll : Boolean. Unselect all nodes & edges before current selection ? Default to TRUE
9#'@param highlightEdges : Boolean. highlight Edges also ? Default to TRUE
10#'@param clickEvent : Boolean. Launch click event ? (highlightNearest for example) Default to TRUE
11#'
12#'@seealso \link{visNodes} for nodes options, \link{visEdges} for edges options, \link{visGroups} for groups options,
13#'\link{visLegend} for adding legend, \link{visOptions} for custom option, \link{visLayout} & \link{visHierarchicalLayout} for layout,
14#'\link{visPhysics} for control physics, \link{visInteraction} for interaction, \link{visNetworkProxy} & \link{visFocus} & \link{visFit} for animation within shiny,
15#'\link{visDocumentation}, \link{visEvents}, \link{visConfigure} ...
16#'
17#' @examples
18#'\dontrun{
19#'
20#'# have a look to :
21#'shiny::runApp(system.file("shiny", package = "visNetwork"))
22#'
23#'}
24#'
25#'@export
26#'@references See online documentation \url{http://datastorm-open.github.io/visNetwork/}
27visSetSelection <- function(graph, nodesId = NULL, edgesId = NULL, unselectAll = TRUE,
28                            highlightEdges = TRUE, clickEvent = TRUE){
29
30  if(!any(class(graph) %in% "visNetwork_Proxy")){
31    stop("Can't use visSetSelection with visNetwork object. Only within shiny & using visNetworkProxy")
32  }
33
34  if(!is.null(nodesId)){
35    if(length(nodesId) == 1){
36      nodesId <- list(nodesId)
37    }
38  }
39
40  if(!is.null(edgesId)){
41    if(length(edgesId) == 1){
42      edgesId <- list(edgesId)
43    }
44  }
45
46  data <- list(id = graph$id, selection = list(nodes = nodesId, edges = edgesId),
47               options = list(unselectAll = unselectAll, highlightEdges = highlightEdges), clickEvent = clickEvent)
48
49  graph$session$sendCustomMessage("visShinySetSelection", data)
50
51  graph
52}
53