【问题标题】:Convert Pajek file to CSV and Display it in R Shiny将 Pajek 文件转换为 CSV 并在 R Shiny 中显示
【发布时间】:2015-07-09 08:33:46
【问题描述】:

有谁知道如何在shiny中读取pajek文件,然后找到每个顶点的度数并按降序输出到CSV文件?

这是我要导入并将学位导出为 CSV 的 Pajek 文件。

在 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 中做到这一点:

这是我到目前为止所做的:

ui.R

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")) 

                           ) 

               )

  )
))

服务器.R

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. 该顶点的度数

【问题讨论】:

    标签: r csv shiny igraph


    【解决方案1】:

    我可能误读了您的脚本,但我认为您需要将所有数据摄取和操作从“server.R”文件的shinyServer() 部分移到它前面的空间。通常,shinyServer() 插槽中的唯一内容是呈现应用程序中的反应元素的代码。这些反应性元素的所有准备工作都应该在致电shinyServer() 之前进行。有关“server.R”脚本的推荐结构的更多信息,请参阅this part of the Shiny tutorial

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 2018-07-04
      • 1970-01-01
      相关资源
      最近更新 更多