@@ -512,7 +512,25 @@ numattr <- reactive({
512512 numattr <- append(numattr ,attrib()[i ])
513513 }
514514 }}
515- numattr })
515+ numattr
516+ })
517+
518+ # dataframe of nodes, their attributes, and their coordinates in nwplot
519+ nwdf <- reactive({
520+ attrs <- menuattr()
521+ if (is.na(as.numeric(network.vertex.names(nw()))[1 ])){
522+ df <- data.frame (Names = network.vertex.names(nw()))
523+ } else {
524+ df <- data.frame (Names = as.numeric(network.vertex.names(nw())))
525+ }
526+ for (i in seq(length(attrs ))){
527+ df [[attrs [i ]]] <- get.vertex.attribute(nw(), attrs [i ])
528+ }
529+ df [[" Missing" ]] <- get.vertex.attribute(nw(), " na" )
530+ df [[" cx" ]] <- coords()[,1 ]
531+ df [[" cy" ]] <- coords()[,2 ]
532+ df
533+ })
516534
517535# betweenness centrality of all nodes (for sizing menu)
518536nodebetw <- reactive({
@@ -1416,34 +1434,52 @@ output$nwplotdownload <- downloadHandler(
14161434 }
14171435 )
14181436
1419- # dataframe of nodes, their attributes, and their coordinates in nwplot
1420- nwdf <- reactive({
1421- attrs <- menuattr()
1422- if (is.na(as.numeric(network.vertex.names(nw()))[1 ])){
1423- df <- data.frame (Names = network.vertex.names(nw()))
1424- } else {
1425- df <- data.frame (Names = as.numeric(network.vertex.names(nw())))
1426- }
1427- for (i in seq(length(attrs ))){
1428- df [[attrs [i ]]] <- get.vertex.attribute(nw(), attrs [i ])
1429- }
1430- df [[" Missing" ]] <- get.vertex.attribute(nw(), " na" )
1431- df [[" cx" ]] <- coords()[,1 ]
1432- df [[" cy" ]] <- coords()[,2 ]
1433- df
1437+ output $ attrcheck <- renderUI({
1438+ checkboxGroupInput(" attrcols" ,
1439+ label = " Include these attributes" ,
1440+ choices = c(menuattr(), " Missing" ),
1441+ selected = c(menuattr(), " Missing" ))
14341442})
1443+ outputOptions(output , " attrcheck" , suspendWhenHidden = FALSE )
14351444
14361445output $ attrtbl <- renderDataTable({
1437- df <- nwdf()
1438- dt <- df [, c(" Names" , input $ attribcols )]
1446+ dt <- nwdf()[, c(" Names" , input $ attrcols )]
14391447 dt
14401448}, options = list (pageLength = 10 ))
14411449
1442- output $ attrcheck <- renderUI({
1443- checkboxGroupInput(" attribcols" ,
1444- label = " Include these attributes in the table" ,
1445- choices = c(menuattr(), " Missing" ),
1446- selected = c(menuattr(), " Missing" ))
1450+ output $ attrhist <- renderPlot({
1451+ nplots <- length(input $ attrcols )
1452+ if (nplots == 0 ){return ()}
1453+ attrname <- input $ attrcols
1454+ if (nplots == 1 ){
1455+ par(mfrow = c(1 , 1 ))
1456+ lvls <- length(unique(nwdf()[[attrname ]]))
1457+ if (attrname %in% numattr() & lvls > 9 ){
1458+ tab <- hist.info(nwdf()[[attrname ]], breaks = 10 )
1459+ } else {
1460+ tab <- table(nwdf()[[attrname ]])
1461+ }
1462+ barplot(tab , xlab = attrname , col = histblue )
1463+ } else {
1464+ r <- ceiling(nplots / 2 )
1465+ par(mfrow = c(r , 2 ))
1466+ for (a in attrname ){
1467+ lvls <- length(unique(nwdf()[[a ]]))
1468+ if (a %in% numattr() & lvls > 9 ){
1469+ tab <- hist.info(nwdf()[[a ]], breaks = 10 )
1470+ } else {
1471+ tab <- table(nwdf()[[a ]])
1472+ }
1473+ barplot(tab , xlab = a , col = histblue )
1474+ }
1475+ }
1476+ })
1477+
1478+ output $ attrhistplotspace <- renderUI({
1479+ nplots <- length(input $ attrcols )
1480+ r <- ceiling(nplots / 2 )
1481+ h <- ifelse(r == 1 , 400 , r * 300 )
1482+ plotOutput(" attrhist" , height = h )
14471483})
14481484
14491485# Data to use for null hypothesis overlays in network plots
0 commit comments