我正在寻找基于单击 actionButton 来呈现和重新呈现 simpleNetwork 图。但是,由于某种原因,多次单击该按钮并不会创建新的 simpleNetwork 实例,而是似乎使用了缓存版本。如何让 simpleNetwork 图表在多次点击时完全重新渲染?
我在下面提供了一个示例以及该问题的 gif:
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)