# NOT RUN {
library(shiny)
ui <- fluidPage(
actionButton("add", "add nodes & edges"),
sigmajsOutput("sg")
)
server <- function(input, output, session){
nodes <- sg_make_nodes()
edges <- sg_make_edges(nodes)
output$sg <- renderSigmajs({
sigmajs() %>%
sg_nodes(nodes, id, label, color, size) %>%
sg_edges(edges, id, source, target) %>%
sg_layout()
})
i <- 10
observeEvent(input$add, {
new_nodes <- sg_make_nodes()
new_nodes$id <- as.character(as.numeric(new_nodes$id) + i)
i <<- i + 10
ids <- 1:(i)
new_edges <- data.frame(
id = as.character((i * 2 + 15):(i * 2 + 29)),
source = as.character(sample(ids, 15)),
target = as.character(sample(ids, 15))
)
sigmajsProxy("sg") %>%
sg_force_kill_p() %>%
sg_read_nodes_p(new_nodes, id, label, color, size) %>%
sg_read_edges_p(new_edges, id, source, target) %>%
sg_read_exec_p() %>%
sg_force_start_p() %>%
sg_refresh_p()
})
}
if(interactive()) shinyApp(ui, server)
# }
Run the code above in your browser using DataLab