为什么 write.csv 在 R shiny 中将 4 列转换为 1 列?

Why does write.csv transform 4 columns to 1 column in R shiny?

我目前正在开发一个项目,我需要在其中将数据框导入导出为 .csv 文件。这是代码:

ui.R

fileInput(
  "file1",
  "Importer depuis un fichier",
  accept = c(
    "text/csv",
    "text/comma-separated-values,text/plain",
    ".csv")
),
rHandsontableOutput("tabl")
downloadButton(
  "imprCsv",
  "Imprimer en CSV"
)

server.R

reactDataBase <- reactiveValues(data = dataBase)
output$tabl <- renderRHandsontable({
  rhandsontable(reactDataBase$data, useTypes = TRUE, stretchH = "all") %>%
  hot_col("Pièce", readOnly = TRUE) %>%
  hot_col("Désignation", readOnly = TRUE)
})

observe({
  inFile <- input$file1
  if(is.null(inFile)) {return(NULL)}
  reactDataBase$data<<-read.table(file=inFile$datapath, header=TRUE, sep=";", na.string="")
})

output$imprCsv <- downloadHandler(
  filename = function() {paste0("Rapport ", str_replace_all(Sys.time(), ":", "_"), ".csv")},
  content = function(file) {
    print(reactDataBase$data)
    write.csv(reactDataBase$data, file)
  }
)

问题是 csv 文件类型不对

    Piece   Name   Value   Minim
1   P2      Picj   12      TRUE
2   P5      Picj   23      TRUE
3   P6      Picj   11      TRUE
4   C15     Calg   9       TRUE
5   X34     Xanol  878     TRUE

但看起来更像:

,"Piece","Name","Value","Minim"
1,"P2","Picj","12","TRUE"
2,"P5","Picj","23","TRUE"
3,"P6","Picj","11","TRUE"
4,"C15","Calg","9","TRUE"
5,"X34","Xanol","878","TRUE"

有什么解决办法吗?

好的,我找到了解决方案。

我只是用 write.csv2 而不是 write.csv