In the server file, I have if statements with reactive functions within. However, I want one of the functions within to be the output. Below, I've included what I have so far.
I highlighted the portion in the last output that requires the defined functions within the if statement. When I run the app, R can't find the function color() because it's nested inside. Is there another way of doing this?
shinyServer(function(input, output) {
observe({
if(input$graph == "advisor"){
s <- reactive({
as.numeric(unlist(neighborhood(g,1,input$advisor)))
})
color = reactive({
ifelse(V(g)$name %in% c(V(g)$name[ s()]), 'red','lightgray')
})
size = reactive({
ifelse(V(g)$name %in% c(V(g)$name[s()]), 3,2)
})
}
})
observe({
if(input$graph == "school"){
index = reactive({
which(SmithDataSet$school_id == input$schools)
})
vertices = reactive({
SmithDataSet$peopleID[index()]
})
color = reactive({
ifelse(V(g)$name %in% vertices(), 'blue','lightgray')
})
size = reactive({
ifelse(V(g)$name %in% vertices(), 3,2)
})
}
})
observe({
if(input$graph == "subject"){
index = reactive({
which(SmithDataSet$code == input$subj)
})
vertices = reactive({
SmithDataSet$peopleID[index()]
})
color = reactive({
ifelse(V(g)$name %in% vertices(), 'green','lightgray')
})
size = reactive({
ifelse(V(g)$name %in% vertices(), 3,2)
})
}
})
output$network = renderPlot({plot(g, layout = my.layout, edge.color = "lightgray", vertex.color = color(), vertex.size = size(),edge.arrow.size = .002, vertex.label=NA)
})
})