Skip to content

Instantly share code, notes, and snippets.

@hinkelman
Last active June 6, 2021 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hinkelman/df2422122a4a0588973dd2af443a1100 to your computer and use it in GitHub Desktop.
Save hinkelman/df2422122a4a0588973dd2af443a1100 to your computer and use it in GitHub Desktop.
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