我编写了一个代码,使用visNetwork软件包在Shiny应用程序中创建网络。在某些情况下,网络会陷入无限循环,试图稳定下来,但从未达到稳定阶段。
我尝试了在visNetwork文档中定义的基于“事件”的选项。试图设置定义的迭代次数以无论如何都停止稳定,并尝试使用双击,单击,选择侦听器以及-> stopStabilization()函数。
visGroups(groupname = "miRNA", shape = "triangle") %>%
visGroups(groupname = "Gene", shape = "circle") %>%
visIgraphLayout(physics = TRUE, smooth = TRUE) %>%
visInteraction(hover = TRUE) %>%
visEvents(type = "on", startStabilizing = "function() { stabilize(iterations = 500) }") %>% ## See below for alternates that did not work
visExport() %>%
visOptions(highlightNearest = TRUE, manipulation = TRUE,
nodesIdSelection = list(enabled = TRUE))%>%
addFontAwesome(name = "font-awesome-visNetwork") %>%
visLegend(addNodes = data.frame(label = c("miRNA", "Gene"), shape = c("triangle","circle"),
size = c(50, 100),
color = c(NA, NA)),
addEdges = data.frame(label = "link"), useGroups = FALSE)
################### I also tried this #######################
visEvents(type = "once", select = "function() { stopStabilization() }") %>% ## Tried to stop with selecting an edge or a node
#############################################################
##################### And this ##############################
visEvents(type = "once", click = "function(e) {
if(e.event.srcEvent.shiftKey){
stopStabilization()
}"}
) %>% ## Tried to stop with shift + click
#############################################################
我的期望是;网络开始稳定,但是如果在达到迭代次数之后网络仍在尝试稳定,则此时将网络暂停。或者,如果用户感到无聊并且想要一个稳定的网络,则单击功能(或其他事件侦听器)应该能够将网络停止在当前状态。
我得到的是;当我尝试添加这些基于“事件”的代码时,未绘制网络,并且看不到任何节点和边缘。