【发布时间】:2015-07-07 07:44:47
【问题描述】:
我有一个表格列表 (df_list)。我想以闪亮的方式将它们导出到 csv。将表列表导出到 csv 时,我在 excel 中打开它们。在 excel 中,表列表被放入列中,并且列由 tablename.colname 引用。我希望以 tble 名称为标题的表具有单独的 col 名称,如下所示。
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
是否还可以在上方添加一个单元格,该单元格提供有关表格的信息,例如 - 实验名称等。它不与其他单元格交互。
我用来生成文件的代码如下:
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
【问题讨论】:
-
仅凭那段代码有点难以回答。我会注意几点: - 1. 你只是定义一个函数来编写一个 csv,而不是在我能看到的任何地方调用它。所以什么都不会发生。 - 2. 尝试编写一个非常小的示例,在一个闪亮的小程序中编写一个玩具 csv 并将其发布。然后我们可以提供更好的帮助。
-
是的,你是对的,代码没有意义我已经编辑为一个工作示例。谢谢迈克
-
好的,让我看看。
标签: r csv shiny export-to-csv