Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 为什么我的网络地图输出没有显示在我的闪亮应用程序中?_R_Shiny_Edges_Visnetwork - Fatal编程技术网

R 为什么我的网络地图输出没有显示在我的闪亮应用程序中?

R 为什么我的网络地图输出没有显示在我的闪亮应用程序中?,r,shiny,edges,visnetwork,R,Shiny,Edges,Visnetwork,我最担心的是它没有出错,只是没有显示出来! 我必须提到,我甚至打印了每一行,以检查进展情况,因为它的进展和所有出来,因为它定期在控制台上。我猜它一定在output$visnetwork函数中,但我不知道 # --------------------------------------- Global --------------------------------------- # # Set working directory -> Ctrl+Shift+H & Open th

我最担心的是它没有出错,只是没有显示出来! 我必须提到,我甚至打印了每一行,以检查进展情况,因为它的进展和所有出来,因为它定期在控制台上。我猜它一定在
output$visnetwork
函数中,但我不知道

# --------------------------------------- Global --------------------------------------- #

# Set working directory -> Ctrl+Shift+H & Open the app folder
setwd("~/Programación en R/Shiny app/Client dashboard app")

# --------------------- Initialize program --------------------- #

# Print in console: global script is beginning to run
print("global.R")


#--------------------------------------- User Interface ---------------------------------------#

# Tell user ui script is beginning to run
print("ui.R")

ui <- fluidPage( 
  theme = shinytheme("cerulean"), 

  navbarPage("Analysis",

             #--- Home Tab (Global View)
             tabPanel("Global View",
                      sidebarPanel(),
                      visNetworkOutput("network")
                      ), #tabPanel - Global View  

             tabPanel("",
                      ) #tabPanel - 

  ) #navbarPage
) #fluidPage
#--------------------------------------- Server ---------------------------------------#

# Tell user server script is beginning to run
print("server.R")

server <- function(input, output, session) {

  # Gathering important variables in one only data set
    twd <<- NULL

  observe({                                                         
    twd <- structure(c(0.0156521739130435, 0, 0, 0, 0, 0, 0.00633484162895928, 
0, 0, 0.0137931034482759, 0.118245390972664, 0, 0.0121739130434783, 
0.141455437448896, 0.00131061598951507, 0, 0.00580720092915215, 
0, 0, 0, 0.0200445434298441, 0, 0, 0, 0, 0, 0, 0.036046511627907, 
0, 0, 0.00180995475113122, 0, 0, 0.0334975369458128, 0.0216147488874762, 
0.0449197860962567, 0.00956521739130435, 0.0834014717906787, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0121739130434783, 0.080130825838103, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0217391304347826, 0, 0, 0, 0, 
0, 0, 0, 0.0623608017817372, 0, 0.00762873490146217, 0, 0, 0, 
0, 0.00930232558139535, 0.0511033681765389, 0, 0, 0, 0.044543429844098, 
0, 0, 0, 0.0582608695652174, 0, 0, 0, 0, 0, 0, 0, 0.0122494432071269, 
0, 0, 0, 0, 0.00245298446443173, 0, 0, 0, 0, 0.0624434389140271, 
0, 0, 0, 0.00190718372536554, 0, 0, 0.00654129190515127, 0, 0, 
0, 0, 0, 0.0594541910331384, 0, 0, 0, 0.00320855614973262, 0.0121739130434783, 
0.00163532297628782, 0, 0.0558139534883721, 0, 0, 0, 0.00584795321637427, 
0, 0, 0, 0, 0, 0, 0, 0.0709302325581395, 0, 0, 0, 0, 0, 0, 0.00190718372536554, 
0, 0, 0, 0, 0, 0, 0, 0.0262443438914027, 0, 0.0089086859688196, 
0, 0.0133502860775588, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0368722186904005, 
0, 0, 0, 0.072083879423329, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0217391304347826, 
0, 0, 0, 0, 0, 0, 0.0126705653021442, 0, 0, 0.0108073744437381, 
0, 0.0165217391304348, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0222504767959313, 
0, 0, 0, 0, 0, 0, 0, 0.0235294117647059, 0, 0.0178173719376392, 
0, 0.00699300699300699, 0, 0, 0.0098119378577269, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0.0427807486631016, 0.00521739130434783, 0.0335241210139002, 
0, 0, 0, 0, 0, 0, 0, 0, 0.00254291163382072, 0, 0, 0, 0, 0, 0, 
0.0488974113135187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0488974113135187, 
0, 0, 0, 0, 0, 0, 0.0182608695652174, 0.0122649223221586, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0.0128342245989305, 0, 0.00408830744071954, 
0, 0, 0, 0.0134228187919463, 0.0262443438914027, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0305149396058487, 0), .Dim = c(12L, 
25L), .Dimnames = list(NULL, c("demand_response", "utility_model", 
"real_time", "model_discloses", "utility_model_discloses", "power_supply", 
"control_system", "control_module", "intelligent_terminal", "management_system", 
"energy_consumption", "disaggregated_model", "control_method", 
"power_grid", "electric_energy", "intelligent_power", "electricity_consumption", 
"power_consumption", "control_unit", "communication_module", 
"random_access", "uplink_frequency", "intelligent_control", "mobile_terminal", 
"power_utilization")))
    topic_names <<- c("1", "2", "3","4","5","6","7","8","9","10","11","12")                         
  })

  # Network Map

  observe({
  # Preparing data with igraph library

    twd_num_col <- ncol(twd)
    cor_threshold <- .8
    twd_cor <- cor(twd[,1:twd_num_col], method = "pearson")
    twd_cor[ twd_cor < cor_threshold ] <- 0
    diag(twd_cor) <- 0
    graph <- graph.adjacency(twd_cor, weighted=TRUE, mode="lower")
    E(graph)$edge.width  <- E(graph)$weight
    V(graph)$group       <- apply(twd, 2, which.max)  #Max topic prob for colors
    V(graph)$betweenness <- betweenness(graph, v = V(graph), directed = F)
    V(graph)$degree      <- degree(graph, v = V(graph))

    # Fit data for visNetwork 
    nm_data <- toVisNetworkData(graph)
    nodes <- nm_data[[1]]
    edges <- nm_data[[2]]
    nodes <- nodes[nodes$degree != 0,]    # Bye topics that don't have a connection (degree = 0)
    nodes$group <- swap(nodes$group , 1:length(topic_names), topic_names) # Swap long real names
    nodes$label <- rep("")
  })

  output$network <- renderVisNetwork({
    # Graph
    set.seed(17);visNetwork(nodes, edges, main = "Relation between topics")  %>% 
      visOptions(highlightNearest = TRUE, selectedBy = "group") %>%
      visInteraction(dragNodes = FALSE) %>%
      visLegend(useGroups = TRUE, main = "Topic", ncol = 2)  %>%
      visNodes(shape = "dot",label = NULL) %>%
      visEdges(smooth = FALSE) %>%
      visIgraphLayout(randomSeed = 17)
  })

}
shinyApp(ui, server)
#-----------------------------------------全局-----------------#
#设置工作目录->Ctrl+Shift+H&打开应用程序文件夹
setwd(“~/Programación en R/shinny应用程序/客户端仪表板应用程序”)
#----------------初始化程序------------------#
#在控制台中打印:全局脚本开始运行
打印(“global.R”)
#---------------------------------------用户界面---------------------------------------#
#告诉用户ui脚本正在开始运行
打印(“ui.R”)

你能提供一个可复制的例子吗?若有,;It’没有显示,肯定需要查看UI以确保您有正确的内容,运行完整的代码也有助于此过程。不确定这是否是您所说的可复制示例,但我只是添加了完整的代码@MelaniaCB这不是一个可复制的示例,因为我们无法访问您的数据或您在脚本开头调用的代码。查看什么是可复制的示例。我所做的只是在创建时将节点和边
标记为.data.frame()
,以及在
visNetwork
中再标记一次。