Plotting reactive Igraph in Rshiny

I am trying to plot a network graph using Rshiny but I want it to be reactive based on the inputs. I have 2 inputs: Workday (Working Days and Non-Working Days) Network Centrality: (Degree, Eigen, Hubs, etc).

The edge attribute has the Workday values so once selected, I intend to remove the edges based on the selection. I will then only display the vertices that belongs to the top 10% based on the quantile function and the centrality selection. I am not too sure why I received an error regarding:

Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context.
• You tried to do something that can only be done from inside a reactive consumer.

UI

ui <- fluidPage(
  
  # Application title
  tabsetPanel(
    
    tabPanel( "Social Interaction",
              # Sidebar with a slider input for number of bins 
              sidebarLayout(
                sidebarPanel(
                  helpText(" Visualise the Social Network Interaction of the Population
          in Ohio"),
                  
                  selectInput(inputId = "workday",
                              label = "Choose a Workday Type",
                              choices = c( "Working Days",
                                           "Non-Working Days"
                              ),
                              selected = "Working Days"),
                  
                  
                  selectInput(inputId = "Network",
                              label = "Choose a Network Centrality Measure",
                              choices = c( "Degree Centrality" = "degree",
                                           "Eigenvector Centrality" = "eig",
                                           "Hub centrality" = "hubs",
                                           "Authority centrality" = "authorities",
                                           "Closeness centrality" = "closeness"
                              ),
                              selected = "degree")
                  
                  
                ),
                mainPanel(
                  plotOutput ("socialPlot")
                )
              )         
              
              
    )
    
  )
  
) 

Server

 server <- function(input, output, session) {
  
  social_data <- reactive ({
    social_graph %>%
      delete_edges(social_graph, which(E(social_graph)$work_day == input$workday)) %>%
      V(social_graph)$degree <- degree(social_graph)                
      V(social_graph)$eig <- evcent(social_graph)$vector              
      V(social_graph)$hubs <- hub.score(social_graph)$vector           
      V(social_graph)$authorities <- authority.score(social_graph)$vector 
      V(social_graph)$closeness <- closeness(social_graph)                
      V(social_graph)$betweenness <- betweenness(social_graph)
      V(social_graph)$color <- ifelse (V(social_graph)$.data[[input$Network]] > quantile(V(social_graph)$.data[[input$Network]],0.9), "darkgoldenrod3", "azure3")
      V(social_graph)$size <- ifelse (V(social_graph)$.data[[input$Network]] > quantile(V(social_graph)$.data[[input$Network]],0.9), 2, 0.05)
      V(social_graph)$label <- ifelse (V(social_graph)$.data[[input$Network]] > quantile(V(social_graph)$.data[[input$Network]],0.9),V(social_graph)$name,NA)
  })
  
  output$socialPlot <- plot.igraph(social_data(),layout=layout.mds, edge.arrow.size=0.1,edge.arrow.mode = "-", vertex.label.cex = 0.65, vertex.label.font = 2)
  
  
  

}


Summary of social_graph


+ attr: name (v/c), Income (v/n), Expenses (v/n), Household_Size (v/n), Have_Kids (v/l), Age (v/n), Education_Level (v/c), Interest_Group (v/c), Joviality (v/n), Age_Group (v/c), work_day (e/c), Weight (e/n)

creation of social_graph

social_graph <- graph_from_data_frame (Social_edge_aggregated,
                                 vertices = Part_nodes_aggregated) %>%
  as_tbl_graph()

random 100 dput(social_edge_aggregated)


structure(list(participantIdFrom = c(409, 166, 397, 15, 35, 388, 
974, 110, 1006, 96, 917, 239, 179, 371, 184, 263, 72, 573, 601, 
105, 1003, 169, 344, 477, 432, 389, 618, 878, 372, 784, 899, 
458, 71, 232, 624, 630, 136, 278, 66, 543, 865, 685, 978, 588, 
436, 361, 250, 94, 739, 135, 672, 199, 417, 488, 1005, 681, 957, 
538, 989, 844, 195, 95, 581, 90, 483, 692, 538, 918, 271, 538, 
400, 240, 704, 531, 971, 410, 990, 609, 543, 115, 483, 317, 613, 
482, 403, 488, 997, 747, 759, 449, 970, 571, 969, 953, 410, 173, 
165, 403, 784, 155), participantIdTo = c(181, 223, 563, 877, 
272, 258, 616, 437, 895, 120, 844, 57, 73, 370, 82, 174, 849, 
103, 485, 30, 690, 820, 931, 411, 571, 624, 778, 841, 851, 104, 
632, 715, 685, 336, 696, 147, 7, 894, 234, 697, 970, 974, 106, 
91, 488, 515, 152, 36, 977, 1000, 796, 613, 438, 916, 160, 659, 
788, 796, 270, 801, 645, 158, 473, 429, 947, 51, 679, 79, 305, 
710, 797, 75, 438, 765, 934, 727, 17, 429, 1009, 779, 456, 730, 
389, 694, 217, 472, 60, 804, 522, 782, 993, 202, 948, 550, 962, 
97, 168, 305, 719, 687), work_day = c("Working Days", "Non-Working Days", 
"Working Days", "Working Days", "Non-Working Days", "Working Days", 
"Non-Working Days", "Non-Working Days", "Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Non-Working Days", "Non-Working Days", 
"Working Days", "Non-Working Days", "Non-Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Working Days", "Working Days", 
"Working Days", "Non-Working Days", "Non-Working Days", "Working Days", 
"Working Days", "Working Days", "Non-Working Days", "Working Days", 
"Non-Working Days", "Working Days", "Working Days", "Working Days", 
"Non-Working Days", "Non-Working Days", "Non-Working Days", "Working Days", 
"Non-Working Days", "Non-Working Days", "Working Days", "Working Days", 
"Non-Working Days", "Non-Working Days", "Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Non-Working Days", "Working Days", 
"Non-Working Days", "Working Days", "Non-Working Days", "Working Days", 
"Non-Working Days", "Working Days", "Non-Working Days", "Working Days", 
"Working Days", "Non-Working Days", "Non-Working Days", "Working Days", 
"Working Days", "Working Days", "Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Working Days", "Working Days", 
"Non-Working Days", "Non-Working Days", "Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days", "Non-Working Days", "Working Days", 
"Non-Working Days", "Non-Working Days", "Non-Working Days", "Non-Working Days", 
"Working Days", "Working Days", "Non-Working Days", "Non-Working Days", 
"Non-Working Days", "Working Days"), Weight = c(11L, 9L, 22L, 
8L, 13L, 10L, 10L, 13L, 7L, 13L, 118L, 29L, 33L, 18L, 32L, 10L, 
20L, 5L, 47L, 4L, 4L, 77L, 5L, 41L, 10L, 31L, 62L, 8L, 2L, 30L, 
11L, 23L, 19L, 11L, 26L, 8L, 60L, 22L, 10L, 33L, 3L, 19L, 6L, 
18L, 40L, 11L, 17L, 11L, 13L, 15L, 4L, 10L, 22L, 11L, 4L, 23L, 
96L, 10L, 35L, 28L, 12L, 33L, 3L, 12L, 8L, 20L, 60L, 5L, 23L, 
10L, 44L, 32L, 10L, 2L, 4L, 11L, 24L, 21L, 4L, 13L, 12L, 17L, 
6L, 12L, 51L, 91L, 7L, 10L, 5L, 23L, 18L, 4L, 3L, 4L, 86L, 21L, 
39L, 13L, 10L, 26L)), row.names = c(NA, -100L), class = c("tbl_df", 
"tbl", "data.frame"))

random 100 dput(Part_nodes_aggregated)

structure(list(Participant_ID = c(814, 854, 302, 592, 683, 517, 
798, 189, 937, 805, 917, 73, 815, 183, 35, 919, 41, 753, 307, 
939, 274, 254, 880, 930, 677, 253, 49, 341, 866, 748, 906, 568, 
499, 913, 720, 620, 456, 117, 238, 812, 435, 534, 995, 916, 1003, 
675, 903, 626, 273, 727, 940, 378, 95, 922, 736, 32, 788, 867, 
760, 820, 849, 618, 578, 536, 740, 840, 557, 1002, 579, 471, 
291, 462, 179, 92, 542, 208, 671, 382, 330, 365, 258, 759, 871, 
910, 72, 864, 212, 566, 844, 1009, 616, 390, 984, 970, 829, 54, 
181, 135, 150, 938), Income = c(64387.75, 63551.71, 65349.14, 
91801.41, 86000.49, 46671.13, 51143.43, 150149.3, 57528.18, 38523.74, 
52100.4, 106800.57, 36646.67, 160717, 30195.03, NA, 30380.1, 
54654.2, 40328.79, 28033.15, 43436.7, 115059.63, 59907.91, 34864.35, 
42322.51, 141087.41, 212131.73, 58858.73, 53030.54, 55457.82, 
38377.83, NA, 102347.3, 59304.52, 31453.12, 42322.81, 30402.53, 
89170.25, 44010.58, 37299.02, 27827.94, 84983.36, 28213.46, 53947.25, 
28202.43, 31560.68, 59591.24, 65650.72, 34122.39, 53225.12, 44339.83, 
44641.8, 56509.86, 59573.1, 40984.24, 89573.45, 37966.39, NA, 
NA, 65816.29, 52239.07, 46380.21, 35264.45, 48642.8, 28228.54, 
63107.56, 41016.65, 33760.82, 50616.89, 109323.38, 40578.22, 
27792.9, 34220.11, 61822.96, 84702.42, 46094.27, 42521.11, NA, 
48190.17, 36373.74, 38761.52, 37141.93, 75544.33, 51762.3, 159976.78, 
NA, 28895.6, 41361.83, 63573.49, 28045.27, 35561.47, 49125.4, 
27822.9, 33897.16, 38167.27, 123820.82, 28483.77, 51813.88, 135709.71, 
27818.53), Expenses = c(-25986.39, -23939.11, -19544.77, -20968.45, 
-15405.21, -22786.25, -26126.31, -8785.43, -16024.19, -25736.18, 
-26778.68, -22864.92, -27096, -10684.54, -24699.04, NA, -23647.26, 
-16355.59, -30125.43, -24747.71, -26639.57, -20451.56, -22398.92, 
-8845.51, -15180.65, -22332.57, -18434.32, -20583.13, -33291.88, 
-11793.62, -27826.49, NA, -16305.13, -20159.65, -25811.56, -27973.22, 
-20470.29, -30167.09, -10760.99, -26345.16, -25415.41, -24405.22, 
-18944.49, -26142.94, -18458.02, -20020.91, -21656.54, -29294.64, 
-26764.15, -20350.22, -17301.11, -31385.23, -22332.96, -21127.33, 
-15724.21, -17939.54, -24356.5, NA, NA, -18055.96, -26531.83, 
-22152.22, -28519.26, -20875.57, -20387.83, -26679.54, -25912.04, 
-15563.71, -30903.94, -9115.42, -23033.92, -23992.87, -25448.29, 
-21136.33, -23543.63, -15553.79, -22301.18, NA, -25065.68, -22215.35, 
-29315.07, -25768.61, -20331.57, -26475.61, -21003.56, NA, -23787.4, 
-24899.98, -26130.53, -22273.26, -24698.06, -29383.52, -22915.43, 
-16928.4, -19801.28, -36478.06, -18998.21, -28674.68, -19075.04, 
-21141.81), Household_Size = c(3, 2, 3, 2, 1, 3, 3, 1, 1, 3, 
2, 3, 3, 1, 3, 2, 3, 1, 3, 1, 3, 3, 2, 1, 1, 3, 3, 2, 2, 1, 2, 
3, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 2, 1, 1, 2, 2, 3, 1, 1, 2, 
2, 2, 1, 3, 3, 2, 3, 3, 2, 2, 3, 3, 1, 2, 3, 1, 2, 1, 3, 1, 1, 
2, 3, 1, 2, 2, 2, 2, 3, 3, 2, 2, 3, 2, 1, 3, 2, 1, 2, 2, 1, 1, 
3, 3, 1, 2, 2, 1), Have_Kids = c(TRUE, FALSE, TRUE, FALSE, FALSE, 
TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, 
FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, 
TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, 
TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 
FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, 
FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE), Age = c(54, 
28, 44, 32, 31, 35, 36, 53, 44, 19, 32, 32, 38, 41, 20, 56, 41, 
21, 38, 35, 44, 23, 49, 41, 47, 43, 54, 34, 42, 26, 22, 52, 28, 
55, 56, 31, 25, 22, 21, 44, 27, 50, 60, 38, 48, 55, 23, 28, 46, 
58, 34, 60, 47, 55, 46, 33, 31, 35, 31, 44, 30, 22, 21, 46, 41, 
47, 18, 51, 48, 36, 37, 60, 44, 43, 27, 56, 51, 43, 25, 20, 37, 
54, 48, 41, 21, 49, 60, 22, 46, 39, 52, 31, 35, 53, 26, 32, 22, 
59, 44, 60), Education_Level = c("Bachelors", "Bachelors", "High School or College", 
"Graduate", "Graduate", "High School or College", "Bachelors", 
"Graduate", "Bachelors", "High School or College", "Bachelors", 
"Bachelors", "High School or College", "Graduate", "Low", "High School or College", 
"High School or College", "Bachelors", "Graduate", "Low", "High School or College", 
"Bachelors", "Bachelors", "High School or College", "High School or College", 
"Graduate", "Graduate", "High School or College", "Bachelors", 
"Graduate", "Bachelors", "Low", "Graduate", "Bachelors", "Graduate", 
"Bachelors", "High School or College", "Bachelors", "Low", "High School or College", 
"Low", "Bachelors", "High School or College", "Bachelors", "High School or College", 
"High School or College", "Bachelors", "Bachelors", "High School or College", 
"Bachelors", "Bachelors", "High School or College", "Low", "Bachelors", 
"High School or College", "High School or College", "High School or College", 
"High School or College", "High School or College", "Bachelors", 
"Bachelors", "High School or College", "Bachelors", "High School or College", 
"High School or College", "Bachelors", "High School or College", 
"High School or College", "Bachelors", "Graduate", "Low", "Low", 
"Bachelors", "High School or College", "Bachelors", "High School or College", 
"High School or College", "High School or College", "Graduate", 
"Low", "Bachelors", "Graduate", "Graduate", "Bachelors", "Bachelors", 
"High School or College", "High School or College", "High School or College", 
"Bachelors", "Low", "High School or College", "Bachelors", "Low", 
"High School or College", "High School or College", "Graduate", 
"High School or College", "High School or College", "Bachelors", 
"High School or College"), Interest_Group = c("F", "B", "A", 
"A", "G", "I", "I", "E", "C", "I", "G", "H", "F", "F", "J", "C", 
"F", "J", "H", "J", "G", "D", "J", "F", "A", "G", "D", "G", "I", 
"E", "E", "C", "I", "J", "C", "A", "H", "F", "A", "F", "C", "F", 
"C", "D", "F", "A", "G", "D", "B", "J", "D", "C", "H", "A", "B", 
"C", "A", "H", "H", "E", "I", "E", "E", "J", "A", "E", "D", "G", 
"F", "J", "E", "H", "F", "J", "D", "E", "C", "H", "G", "G", "G", 
"I", "I", "D", "B", "I", "D", "C", "H", "B", "J", "J", "I", "E", 
"B", "I", "E", "E", "H", "F"), Joviality = c(0.44174758, 0.042899175, 
0.254585434, 0.22126511, 0.241410497, 0.460451549, 0.96008167, 
0.216100876, 0.240105908, 0.328587955, 0.431612119, 0.381370977, 
0.521630433, 0.109940826, 0.707950782, 0.283020728, 0.863663966, 
0.339503386, 0.962210067, 0.880292697, 0.79265137, 0.17968177, 
0.021946709, 0.203002706, 0.137446199, 0.560328176, 0.229589642, 
0.227355255, 0.997670843, 0.874661744, 0.930669564, 0.812872098, 
0.494442294, 0.000265, 0.930475595, 0.673541165, 0.685091778, 
0.760663448, 0.256101892, 0.619525261, 0.725281643, 0.298257944, 
0.444802157, 0.784906863, 0.336785107, 0.545251458, 0.210131243, 
0.793880506, 0.874083512, 0.945430646, 0.807027625, 0.991810222, 
0.451218504, 0.046984156, 0.130649539, 0.189498641, 0.415138085, 
0.709526793, 0.751787305, 0.065357535, 0.828259584, 0.089915241, 
0.98284777, 0.137689076, 0.409040073, 0.469113963, 0.540412762, 
0.323610205, 0.768714853, 0.039582663, 0.370084679, 0.773790326, 
0.900831449, 0.467868166, 0.149424876, 0.371925591, 0.270624129, 
0.964579432, 0.7738118, 0.438986616, 0.951577316, 0.880468848, 
0.067887485, 0.652990074, 0.218744284, 0.416211045, 0.748988452, 
0.401423701, 0.659909909, 0.828330134, 0.544782269, 0.76530714, 
0.969600048, 0.129766383, 0.280151127, 0.778504463, 0.787497465, 
0.86081073, 0.20807405, 0.679262409), Age_Group = structure(c(8L, 
3L, 6L, 4L, 4L, 4L, 5L, 8L, 6L, 1L, 4L, 4L, 5L, 6L, 1L, 9L, 6L, 
2L, 5L, 4L, 6L, 2L, 7L, 6L, 7L, 6L, 8L, 4L, 6L, 3L, 2L, 8L, 3L, 
8L, 9L, 4L, 2L, 2L, 2L, 6L, 3L, 7L, 9L, 5L, 7L, 8L, 2L, 3L, 7L, 
9L, 4L, 9L, 7L, 8L, 7L, 4L, 4L, 4L, 4L, 6L, 3L, 2L, 2L, 7L, 6L, 
7L, 1L, 8L, 7L, 5L, 5L, 9L, 6L, 6L, 3L, 9L, 8L, 6L, 2L, 1L, 5L, 
8L, 7L, 6L, 2L, 7L, 9L, 2L, 7L, 5L, 8L, 4L, 4L, 8L, 3L, 4L, 2L, 
9L, 6L, 9L), levels = c("20 & Below", "21-25", "26-30", "31-35", 
"36-40", "41-45", "46-50", "51-55", "56-60"), class = "factor")), row.names = c(766L, 
797L, 296L, 571L, 647L, 503L, 753L, 189L, 863L, 759L, 846L, 74L, 
767L, 183L, 36L, 848L, 42L, 717L, 301L, 865L, 272L, 254L, 817L, 
856L, 641L, 253L, 50L, 335L, 806L, 712L, 836L, 550L, 487L, 842L, 
684L, 594L, 444L, 118L, 238L, 764L, 423L, 519L, 921L, 845L, 929L, 
639L, 833L, 599L, 271L, 691L, 866L, 370L, 96L, 851L, 700L, 33L, 
747L, 807L, 723L, 769L, 792L, 592L, 558L, 521L, 704L, 783L, 540L, 
928L, 559L, 459L, 287L, 450L, 179L, 93L, 526L, 208L, 635L, 373L, 
324L, 357L, 257L, 722L, 811L, 840L, 73L, 804L, 212L, 548L, 787L, 
935L, 591L, 380L, 910L, 896L, 775L, 55L, 181L, 136L, 150L, 864L
), class = "data.frame")

You cant access social_data here as a reactive function i.e. () nevause you lack a reavtive context. I.e. you need to be within the braces of a reactove contexts.
Typical reactive contexts are things like, a reactive() definition, the expression body of an observe(), and for outputs... a render type function.

My asumption is that you have omitted an approriate render function for what you are plotting. If its not a pure base r plot then in the ui it should also not be a plotOutput place holde, but rather the appropriate counterpart for the render function.

Hi, could you explain more what do you mean it should also not be a plotOutput?

I am trying to visualise a network graph and the nodes and vertex should change based on the different centrality measure I choose.

it may or may not be, it depends whether it produces base r plots, or if it doesn't.
Eitherway my main point stands, that some render* function, must be used.