ndtv 和 r shiny:节点标签不显示

ndtv and r shiny: labels for nodes do not show up

我创建了这个应用程序:https://usaskssrl.shinyapps.io/AnnualReport_2017_18/

我正在尝试在 R 中制作一个闪亮的网络动态可视化(选项卡:网络分析,加载需要几分钟)

一切看起来都很好但是节点没有任何标签

我不负责应用程序的这一部分,但这是供您参考的代码(也可以通过我的存储库访问 - 请参阅下面的 link)

Global.R(第 225 行):

library(ndtv)
library(network)  
#SOCIAL NETOWORK ANALYSIS

 nodes <- read.csv   (text=getURL("https://raw.githubusercontent.com/AhmadMobin/SSRL201712018/master/ssrlNODES17%2618%5B1%5D.csv"),header = TRUE, stringsAsFactors = FALSE, fileEncoding = "UTF-8")

 links <-  read.csv  (text=getURL("https://raw.githubusercontent.com/AhmadMobin/SSRL201712018/master/ssrlEDGES17%2618%5B1%5D.csv"),header = TRUE, stringsAsFactors = FALSE, fileEncoding = "UTF-8")  

 net3 <- network(links, vertex.attr=nodes, matrix.type="edgelist",
            loops=F, multiple=F, ignore.eval = F)

 net3[,]
 net3 %n% "net.name" <- "SSRL Network" # network attribute
 net3 %v% "group" # Node attribute
 net3 %e% "value" # Edge attribute

 net3 %v% "col" <- c("blueviolet", "blue", "red", "midnightblue")[net3 %v% "group"]
 plot(net3, vertex.cex=(net3 %v% "size")/7, vertex.col="col")

 vs <- data.frame(onset=0, terminus=204, vertex.id=1:88)
 es <- data.frame(onset=1:203, terminus=204,
             head=as.matrix(net3, matrix.type="edgelist")[,1],
             tail=as.matrix(net3, matrix.type="edgelist")[,2])

 net3.dyn <- networkDynamic(base.net=net3, edge.spells=es, vertex.spells=vs)

Server.R(第 216 行):

 #NETWORK ANALYSIS
 output$netPlot <- ndtv:::renderNdtvAnimationWidget({
    render.d3movie(net3.dyn, usearrows = F,
                   displaylabels = F, label=net3 %v% "group",
                   bg="#ffffff", vertex.border="#333333",
                   vertex.cex = net3 %v% "size"/10,
                   vertex.col = net3.dyn %v% "col",
                   edge.lwd = (net3.dyn %e% "value")/10,
                   edge.col = '#55555599',
                   vertex.tooltip = paste("<b>Name:</b>", (net3.dyn %v% "name") , "<br>",
                                          "<b>Group:</b>", (net3.dyn %v% "group.name")),
                   edge.tooltip = paste("<b>Number of Collaborations:</b>", (net3.dyn %e% "value" )),
                   #launchBrowser=T, filename="SSRL SNA 2017 and 2018.html", #don't think this line is needed
                   render.par=list(tween.frames = 30, show.time = F), output.mode = 'htmlWidget')
   }
   )

Ui.R(第 129 行):

 tabItem(tabName="sixth",
                      h5("Note: This will take a few minutes to load"),
                      HTML ('</br>'),
                      ndtv:::ndtvAnimationWidgetOutput("netPlot")
                      )
            )) 
 ) 

这不是我的代码,但如果你们有任何清理它的建议,我也将不胜感激!

我的 GitHub 仓库可以在这里找到:https://github.com/AhmadMobin/SSRL201712018

好吧,我找到了解决办法。

我创建了网络动画,输出为 HTML。我在线托管了该动画并将我的应用程序指向该网页。如果您单击 "Network Analysis" 选项卡,您就会明白我的意思 https://usaskssrl.shinyapps.io/AnnualReport_2017_18/ http://ssrl.usask.ca/documents/SSRL%20SNA%202017%20and%202018.html

感兴趣的朋友,这里是动画的代码

library(ndtv)
library(network)
library(RCurl) #package for the get URL function 

nodes <- read.csv (text=getURL(https://raw.githubusercontent.com/AhmadMobin/SSRL201712018/master/ssrlNODES17%2618%5B1%5D.csv"),header = TRUE, stringsAsFactors = FALSE, fileEncoding = "UTF-8")

links <- read.csv (text=getURL("https://raw.githubusercontent.com/AhmadMobin/SSRL201712018/master/ssrlEDGES17%2618%5B1%5D.csv"),header = TRUE, stringsAsFactors = FALSE, fileEncoding = "UTF-8")


 net3 <- network(links, vertex.attr=nodes, matrix.type="edgelist",
            loops=F, multiple=F, ignore.eval = F)

 net3[,]
 net3 %n% "net.name" <- "SSRL Network" # network attribute
 net3 %v% "group" # Node attribute
 net3 %e% "value" # Edge attribute

 net3 %v% "col" <- c("blueviolet", "blue", "red", "midnightblue")[net3 %v% "group"]
 plot(net3, vertex.cex=(net3 %v% "size")/7, vertex.col="col")

 vs <- data.frame(onset=0, terminus=204, vertex.id=1:88)
 es <- data.frame(onset=1:203, terminus=204,
             head=as.matrix(net3, matrix.type="edgelist")[,1],
             tail=as.matrix(net3, matrix.type="edgelist")[,2])
  net3.dyn <- networkDynamic(base.net=net3, edge.spells=es, vertex.spells=vs)

 compute.animation(net3.dyn, animation.mode = "kamadakawai",default.dist=2,
              slice.par=list(start=0, end=203, interval=1,
                             aggregate.dur=1, rule='any'))
 render.d3movie(net3.dyn, usearrows = F,
           displaylabels = F, label=net3 %v% "group",
           bg="#ffffff", vertex.border="#333333",
           vertex.cex = net3 %v% "size"/10,
           vertex.col = net3.dyn %v% "col",
           edge.lwd = (net3.dyn %e% "value")/10,
           edge.col = '#55555599',
           vertex.tooltip = paste("<b>Name:</b>", (net3.dyn %v% "name") , "<br>",
                                  "<b>Group:</b>", (net3.dyn %v% "group.name")),
           edge.tooltip = paste("<b>Number of Collaborations:</b>", (net3.dyn %e% "value" ) ),
           launchBrowser=T, filename="SSRL SNA 2017 and 2018.html",
           render.par=list(tween.frames = 30, show.time = F))