- 嗨,我试图从一个独特的excel文件下载多个csv文件。我想下载(只使用一个下载按钮)从excel文件不同的工作表。我不明白为什么一个for()循环不工作,我不知道我该怎么做?如果有人知道..
重点是下载不同的csv文件,它们都在"wb"列表中(wb [1],wb [2]...)谢谢。下面是我的代码,例如第三张表(抱歉我的英语不好):用户界面:
library(readxl)
library(shiny)
library(XLConnect)
fluidPage(
titlePanel("Export onglets en CSV"),
sidebarLayout(
sidebarPanel(
fileInput('fichier1','Choisissez votre fichier excel :',
accept = ".xlsx"),
fluidPage(
fluidRow(
column(width = 12,
numericInput("sheet","Indiquez l'onglet à afficher :",min = 1, value = 1),
tags$hr(),
textInput('text',"Indiquez le nom des fichiers :"),
tags$hr(),
h4("Pour télécharger les fichiers .csv :"),
downloadButton("download","Télécharger")
)
)
)),
mainPanel(
tabsetPanel(
tabPanel('Importation',
h4("Fichier de base:"),
dataTableOutput("contents"))
)
)
)
)
服务器:
function(input,output){
#Création data :
data <- reactive({
inFile<- input$fichier1
if (is.null(inFile)){
return(NULL)
}else{
file.rename(inFile$datapath,
paste(inFile$datapath,".xlsx", sep =""))
wb = loadWorkbook(paste(inFile$datapath,".xlsx",sep=""))
lst = readWorksheet(wb,sheet = getSheets(wb))
list(wb = wb, lst = lst)
}
})
#Sortie de la table :
output$contents <- renderDataTable({
data()$wb[input$sheet]
},options = list(pageLength = 10))
#Téléchargement :
output$download <- downloadHandler(
#for (i in 1:input$sheet){
filename = function(){
paste(input$text,"_0",3,".csv",sep = "")
},
content = function(file){
write.table(data()$wb[3],file,
sep = ';', row.names = F, col.names = T)
}
#}
)
}
3条答案
按热度按时间ghhaqwfi1#
正如@BigDataScientist所指出的,你可以压缩所有的csv文件,然后下载压缩后的文件,你的
downloadHandler
可能看起来像这样:这不会从excel文件中下载所有工作表,但会下载从1到用户在
input$sheet
中输入的任何工作表。如果用户尚未添加excel文件/名称,您也可以禁用下载按钮。
aydmsdu92#
希望你已经解决了这个问题,但是如果其他人也有类似的问题,这种情况下是因为RTools没有正确安装在Windows上。
目前,您需要在运行安装过程时密切关注,并确保选中复选框以编辑系统路径。
根据您的代码,这很可能是阻止您保存XLSX工作簿的同一问题。
ujv3wf0j3#
我知道这是一个老线索,但我有同样的问题,顶部的答案对我不起作用。然而,一个简单的调整和使用存档包工作。
可重现示例如下:
这将创建包含
iris.csv
和mtcars.csv
的zip文件myzipfile.zip
。