PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

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

 September 18, 2022     csv, dataframe, printing, r, shiny     No comments   

Issue

I am currently working on a project using in which I need to import an export a data frame as a .csv file. Here is the code:

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

The problem, here is that the csv file isn't of type

    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

But it looks more like:

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

Any solution?


Solution

Ok, I found the solution.

I just used write.csv2 instead of write.csv👌



Answered By - TFC
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing