简体   繁体   English

在 visNetwork 中的 Shiny 中以编程方式取消选择边缘

[英]Deselect edges programmatically in Shiny in visNetwork

I want to deselect edges in a visNetwork network in Shiny.我想在 Shiny 的 visNetwork 网络中取消选择边。 visSetSelection should work, but it doesn't: if I select an edge manually, then press the button, the edge remains selected. visSetSelection应该工作,但它没有:如果我手动选择一个边缘,然后按下按钮,边缘保持选中状态。 I don't know of any other way to do it.我不知道还有什么其他方法可以做到。 This https://github.com/almende/vis/issues/1670 suggests using visSelectEdges and setting the id to NULL but this also has no effect.这个https://github.com/almende/vis/issues/1670建议使用 visSelectEdges 并将 id 设置为 NULL 但这也没有效果。 Any ideas?有任何想法吗?

require(shiny)
require(visNetwork)

server <- function(input, output) {
  output$network <- renderVisNetwork({
    # minimal example
    nodes <- data.frame(id = 1:3)
    edges <- data.frame(from = c(1,2), to = c(1,3))

    visNetwork(nodes, edges)
  })

  observeEvent("deselect",{
  visNetworkProxy("network") %>%
    visSetSelection(edgesId = NULL,unselectAll = T) 


})
}

ui <- fluidPage(
  visNetworkOutput("network"),
  actionButton("deselect","Deselect")
)

shinyApp(ui = ui, server = server)

You can use visUnselectAll (see here ).您可以使用visUnselectAll (请参阅此处)。 Also, you need to replace "deselect" by input$deselect in the condition of observeEvent .此外,您需要在observeEvent的条件下用input$deselect替换"deselect"

require(shiny)
require(visNetwork)

server <- function(input, output) {
  output$network <- renderVisNetwork({
    # minimal example
    nodes <- data.frame(id = 1:3)
    edges <- data.frame(from = c(1,2), to = c(1,3))

    visNetwork(nodes, edges)
  })

  observeEvent(input$deselect, {
    visNetworkProxy("network") %>%
      visUnselectAll()

  })
}

ui <- fluidPage(
  visNetworkOutput("network"),
  actionButton("deselect","Deselect")
)

shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM