I am relatively new to R and I wonder how to create a reactive igraph in shiny. I am trying to build a shiny app that analyzes Airbnb data. Overall I want to visualize a bipartite network that shows the connection between the listing_id of the apartment and the reviewer_id of the reviewer in an interactive fashion.
I tried to base the graph on a reactive filter that filters the data based on a neighborhood (input from the UI). The graph itself should show connections between listing_ids based on common reviewer_ids (i.e. Listing A is connected to Listing B if they have at least 1 reviewer in common).
The code that I have so far is:
#---------------UI----------
ui <- fluidPage(
  sidebarLayout(position = "right",
    sidebarPanel(h3("Input Parameters"),
                 selectInput("neighborhood.selection", "Select the neighborhood you want to display", 
                             c("Manhattan", "Brooklyn", "Queens", "Staten Island",
                               "Bronx")),
                 #textOutput("o.neighborhood.selection"),
                 #selectInput("vertex.selection", "Select the Vertex you want to display", 
                             #c("Reviewer ID" = 1, "Listing ID" = 2)),
                 ),
    mainPanel(h2("Overall Network Graph"),
              plotOutput("o.big.network")
              )
  ),
)
#-----------server----------
library(igraph)
library(shiny)
library(data.table)
library(rsconnect)
library(dplyr)
dt.merged <- readRDS("dt.merged.final.rds")
dt.merged$reviewer_id <- paste0("0", dt.merged$reviewer_id)
dt.merged <- dt.merged[1:500]
server <- function(input, output) {
dt.merged.reactive <- reactive({
  req(input$neighborhood.selection)
  filter(dt.merged,neighbourhood_group_cleansed %in% input$neighborhood.selection)
})
  all.listings <- dt.merged.reactive()[, list(name=unique(listing_id), type=TRUE)]
  all.reviewers <- dt.merged.reactive()[, list(name=unique(reviewer_id), type=FALSE)]  
  all.vertices <-   list(all.listings,all.reviewers)
  output$o.big.network  <- renderPlot({
    # Creating the graph
    g <- graph.data.frame(dt.merged.reactive()[, list(listing_id, reviewer_id)], directed=FALSE, vertices= all.vertices) 
  })
}
