Create interactive ggraph tree with ggiraph package in RShiny app

175 views Asked by At

I am trying to create an interactive ggraph tree plot (or network plot) using the ggiraph package. Previously I used the plotly package but hat didnt work since plotly doesnt support drawing edges.

For the ggiraph package I can get the graph to appear but I have nowhere to add a "tooltip" argument or data_id argument since ggraph uses 'geom_node_point' or 'geom_node_text' which do not have an equivalent 'geom_..._interactive' in the ggiraph package.

# Packages ----------------------------------------------------
library(shiny)
library(plotly)
library(ggraph)
library(igraph)
library(ggiraph)

edges <- data.frame(c("Start", "Start"), c("P1", "P2"))
colnames(edges) <- c("from", "to")

vert <- data.frame(c("Start", "P1", "P2"), c(1, 2, 3), c("this", "is", "info"))
colnames(vert) <- c("name", "Value", "Info")

# Ui ---------------------------------------------------------
ui <- fluidPage(
  girafeOutput(outputId = "tree_plot_out")
)

# Server -----------------------------------------------------
server <- function(input, output, session) {
  #create Tree plot
  tree_plot <- reactive({
    g <- graph_from_data_frame(edges, vertices = vert) 

    ggraph(g) +
      geom_edge_link() +
      geom_node_point(aes(col = V(g)$Value)) +
      geom_node_text(aes(label =  V(g)$Info), size = 5, nudge_y = -0.1)
  })

  # output tree plot
  output$tree_plot_out <- renderGirafe({
    girafe(ggobj = tree_plot())
  })

}

shinyApp(ui = ui, server = server)

This is a reduced example with how I draw the interactive giraph plot. However I cant add the argument "tooltip" anywhere to display info on hovering. Neither can I use the data_id function exeplified on the giraph website https://davidgohel.github.io/ggiraph/articles/offcran/shiny.html

How can I create an interactive plot from this? Is there a workaround for plotly?

0

There are 0 answers