I'm looking to render and re-render a simpleNetwork graph based on clicking an actionButton . However, for some reason, clicking the button multiple times does not create a new simpleNetwork instance, but rather seems to use a cached version. How do I get simpleNetwork graphs to re-render entirely on multiple clicks?
I've included an example below as well as a gif of the issue:
library(shiny)
library(networkD3)
server <- function(input, output, session) {
data <- eventReactive(input$click, {
src <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)
})
output$simple <- renderSimpleNetwork({
simpleNetwork(data())
})
}
ui <- fluidPage(titlePanel("networkD3 + Shiny"),
sidebarLayout(
sidebarPanel(actionButton("click", "Render")),
mainPanel(simpleNetworkOutput(
"simple", width = "100%", height = "700px"
))
))
shinyApp(ui = ui, server = server)
This was already reported here. It was fixed with PR #179 and released in version 0.4 on CRAN. Make sure your networkD3 package is updated.