visNetwork: How do I extract visGetPositions() from shiny into R coordinates matrix?

Viewed 1007
require(shiny)
require(visNetwork)

server <- function(input, output) {

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

    visNetwork(nodes, edges) %>% visNodes(color = "green")
  })

  output$test <- renderPrint({
    input$network_positions
  })
  observe({
    input$goButton
    visNetworkProxy("network") %>%
      visGetPositions()
  })

}

ui <- fluidPage(
  fluidRow(
    column(10,visNetworkOutput("network", height = "100%"),
           verbatimTextOutput("test")),
    column(2, actionButton("goButton", "Go!"))
  )

)

shinyApp(ui = ui, server = server)

So visGetPositions only works in shiny. After you press Go, it calculates and prints out positions of each node. How do I extract it into R matrix so I can use it as coordinates?

1 Answers
Related