簡體   English   中英

將Pajek文件轉換為CSV並在R Shiny中顯示

[英]Convert Pajek file to CSV and Display it in R Shiny

有誰知道如何閃亮地讀取pajek文件,然后找到每個頂點的度並將其以降序輸出到CSV文件?

這是我要導入的Pajek文件,並將度導出為CSV。

在R中,我知道通常如何這樣編碼:

#read the pajek file in igraph
reponetwork <- read.graph("network.net", format = "pajek")

#Inspect the data:
degree(reponetwork)
sort(degree(reponetwork), decreasing = TRUE)

但是我不確定如何在Shiny中執行此操作:

到目前為止,這是我所做的:

用戶界面

shinyUI(fluidPage(
  titlePanel("Finding most influential vertex in a network"),

  sidebarLayout(
    sidebarPanel(

     fileInput("graph", label = h4("Pajek file")),

      downloadButton('downloadData', 'Download')

    ),
    mainPanel( tabsetPanel(type = "tabs", 
                           tabPanel("Table", tableOutput("view")) 

                           ) 

               )

  )
))

服務器

library(igraph)
options(shiny.maxRequestSize=100*1024^2) 

shinyServer(
  function(input, output) {

    filedata <- reactive({
      inFile = input$graph
      if (!is.null(inFile))
      data <<- read.graph(file=inFile$datapath, format="pajek")
    })


   output$view <- renderTable({
  if(is.null(filedata())) {
    return()
  }
  df <- filedata()
  vorder <-sort(degree(df), decreasing=TRUE)
  DF <- data.frame(ID=V(df)[vorder], degree=degree(df)[vorder])
})

    output$downloadData <- downloadHandler(
  filename = function() {
    paste(input$graph, '.csv', sep='')
  },

  # This function should write data to a file given to it by
  # the argument 'file'.
  content = function(file) {
  write.csv(DF, file)
      } 

    )
      }) 

我不確定如何從讀取圖的filedata()方法中獲取文件,然后獲取pajek文件的度數,然后將其輸出到CSV文件中,其中度數最高的是底部,最低的是。

並且所需的CSV文件列應具有:1.頂點ID 2.該頂點的度

我可能會誤讀您的腳本,但是我認為您需要將所有數據提取和操作都從“ server.R”文件的shinyServer()部分移到它之前的空間。 通常, shinyServer()插槽中唯一shinyServer()東西是在應用程序中呈現反應式元素的代碼。 這些反應性元素的所有准備工作都應在調用shinyServer() 有關“ server.R”腳本的推薦結構的更多信息,請參見Shiny教程的這一部分

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM