Interactive network graphs in R Shiny
Install Shiny alongside garphieldr:
install.packages("shiny")Render a graph
Section titled “Render a graph”library(shiny)library(garphieldr)
ui <- fluidPage( garphieldOutput("network"), verbatimTextOutput("clicked"))
server <- function(input, output, session) { project <- garphield_project( edges = data.frame(source = c("a", "b"), target = c("b", "c")) ) output$network <- renderGarphield(project) output$clicked <- renderPrint(input$network_node_click)}
shinyApp(ui, server)A node click arrives as input$network_node_click.
Update the mounted graph
Section titled “Update the mounted graph”Create a proxy when server code needs to replace the project or run a Garphield command:
proxy <- garphieldProxy("network", session)garphieldProxySetProject(proxy, project)garphieldProxyRun(proxy, "setTheme", list(colorScheme = "dark"))garphieldProxyOpenApp(proxy) hands the current project to the full Garphield
workbench.
The igraph to Quarto and Shiny tutorial builds a complete app step by step.