R Shiny - Duplication of visNetwork::visConfigure() Container

22 Views Asked by At

I'm using the visNetwork package with R Shiny.
visNetwork::visConfigure() allows you to specify a container for various configuration options.
For example, I'm using something like this:
visNetwork::visConfigure(enabled = TRUE, filter = "physics", container = "container_div")
This allows me to put the configurable physics options into a targeted div anywhere on the page.

The problem I'm running into is that each time I update the visNetwork() graph itself, it keeps regenerating another duplicate set of same options into the container. Not sure how to keep it to just ONE instance after each update of the graph.

Below is a reproducible example (save the code into app.R). Increment the 'Num Nodes' input, and notice each time you do that, it creates a new set of configuration options at far right; they just continue to stack on top of each other.


require(shiny)
require(visNetwork)

server <- function(input, output) {
  
  output$mynetworkid <- renderVisNetwork({
    
    #minimal nodes/edges
    nodes <- data.frame(id = 1:input$numNodes)
    edges <- data.frame(from = c(1,2), to = c(2,3))
    
    #build network with specific div container location
    visNetwork(nodes, edges) %>% 
      visConfigure(
        enabled = TRUE, 
        filter = "physics", 
        container = "container_div"
      )
  })
}

ui <- fluidPage(
  sidebarLayout(
    
    sidebarPanel(
      width = 2,
      numericInput("numNodes", label = "Num Nodes", value = 3)
    ),
    
    mainPanel(
      column(width = 5, visNetworkOutput("mynetworkid")),
      column(width = 7, div(id = "container_div"))    
    )
  )
)

shinyApp(ui = ui, server = server)

Appreciate any help!

0

There are 0 best solutions below