将表导出到 csv- 列表中的分隔表 - 闪亮

Exporting tables to csv- separating tables in a list- shiny

我有一个 table 的列表 (df_list)。我想将它们导出到闪亮的 csv。将 table 的列表导出到 csv 时,我在 excel 中打开它们。在 excel 中,table 的列表被放入列中,而列则由 tablename.colname 引用。我想让 tables 以带有单独的列名称的表名称为首,如下所示。

 Cy3 control
          Cy5     Cy3    Cy5   Cy3
    Min.    0   14170   6043    15
    1st Qu. 1   14710   6329    16
    Median  1   14960   6833    16
    Mean    3.2 15190   6679    16.47
    3rd Qu. 4.5 15830   7008    17
    Max.    15  16070   7309    19

    Cy3.control.Cy5 Cy3.control.Cy3 Cy5.control.Cy5 Cy5.control.Cy3
Min.              0             170        6043              15
1st Qu.           1           14710        6329              16
Median            1           14960        6833              16
Mean            3.2           15190        6679           16.47
3rd Qu.         4.5           15830        7008              17
Max.             15           16070        7309              19

是否可以在上方添加一个单元格,其中提供有关 table 的信息,例如实验名称等。不与其他单元格交互。

我用来生成文件的代码如下:

UI.R:

shinyUI(fluidPage(
  fluidRow(
    column(4,
             fileInput("rawdata", "Enter your .csv file"),
             br,
             textInput('table_name', 'Data table name to save'),
             downloadButton('downloadtable', 'Save data table to .csv')
             ),

  ) #end fluidrow
 )  ### Fluid page end 
)    #### Shiny UI end

Server:


  #### Initiate shinyServer
  shinyServer(function(input, output) {

    ### This reactive function will take the input "inFile" from the UI.R and store it as data
    inFile<-reactive({
      file1<-input$rawdata
      if(is.null(file1)) stop ("Please Upload a Valid .csv file")
      datas<-fread(file1$datapath,)


      dtableInput<- reactive({
        if(is.null(inFile())) 
          return()

        datas<-inFile()        

        ## apply the following functions over the list

        df_list<-lapply(df_list,function(x){

          ## store the summaries of the Cy5 and Cy3 by block

          Cy5<-summary(x$y1)

          Cy3<-summary(x$y2)

          cbind(y1,y2)    

        })


      })

      output$downloadtable<-downloadHandler(                             #### called from UI
        filename = function() {paste(input$table_name, '.csv', sep='')},
        content = function (file){
          write.csv(dtableInput(),file)
        })

    }) ## end of app

好的,花了一些时间,因为我以前从未使用过 Shiny 的 fileInputdownLoad 按钮。基本上我下面的 post 可能接近你想要的。它允许您select上传一个文件,然后选择一个地方下载它。

我没有建立你的汇总表,我想你可以自己处理它,它会混淆文件处理问题。

需要注意的是,它在普通的 RStudio 查看器中不起作用(可能是错误?它不会保存文件),您必须使用浏览器(单击 运行 App 旁边的下拉菜单按钮和 select Run External(见下面的屏幕截图)

ui.R:

shinyUI(fluidPage(
  fluidRow(
     column(4,
            fileInput("rawdata", "Enter your .csv file"),
            br(),
            textInput('table_name', 'Data table name to save'),
            downloadButton('downloadtable', 'Save data table to .csv')
      )

  ) #end fluidrow
)  ### Fluid page end 
)    #### Shiny UI end

server.R:

#### Initiate shinyServer
shinyServer(function(input, output) {


  inFile<-reactive({
    file1<-input$rawdata
    if(is.null(file1)) stop ("Please Upload a Valid .csv file")
    datas<-read.csv(file=file1$datapath)
  })

  dtableInput<- reactive({
    if(is.null(inFile())) 
      return()
    datas<-inFile()        
  })

    output$downloadtable<-downloadHandler(        #### called from UI
      filename = function() {paste(input$table_name, '.csv', sep='')},
      content = function(file) {
        write.csv(dtableInput(), file)
      }
    )
  })