Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(shiny)
library(dplyr)
library(visNetwork)
edges <- readr::read_tsv("https://raw.githubusercontent.com/hinkelman/dataframe/master/network-graph/Edges.tsv",
col_names = FALSE) %>%
setNames(c("from", "to"))
nodes <- readr::read_tsv("https://raw.githubusercontent.com/hinkelman/dataframe/master/network-graph/Nodes.tsv",
col_names = FALSE) %>%
setNames(c("label", "id")) %>%
left_join(readr::read_tsv("https://raw.githubusercontent.com/hinkelman/dataframe/master/network-graph/NodesByFile.tsv",
col_names = FALSE) %>%
setNames(c("group", "label"))) %>%
# not a fan of the default legend look; so putting that information in title, which is available through hover/click
mutate(title = paste0(label, "<br>", group))
# Define UI for application that draws a histogram
ui <- fluidPage(
fluidRow(col = 12, visNetworkOutput("networkGraph", height = "800px"))
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$networkGraph <- renderVisNetwork({
nodes %>%
visNetwork(edges) %>%
visEdges(arrows = "to") %>%
visOptions(highlightNearest = TRUE,
nodesIdSelection = TRUE)
})
}
# Run the application
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment