R Shiny download data encoding issue

扶醉桌前 提交于 2019-12-13 15:24:32

问题


Maybe it is a silly question but I am really confused. We have Shiny server running on Linux system and set language = UTF-8 to ensure it shows special characters correctly (e.g. 谭盾, いきも,Acatlán de Pérez Figueroa). However, when I tried to download the data (I have a download button utilizing write.csv function), those special characters got mess up.

When I specify the encoding, it works well for both Windows and Mac systems, meaning both Windows and Mac users are able to download correct data from the Shiny page.

It first allows users to upload data and then manipulate and download it eventually. Below is the simplified example:

#upload data

filedata <- reactive({
infile <- input$file
if (is.null(infile)) {
  # User has not uploaded a file yet
  return(NULL)
}
fread(infile$datapath, encoding = "UTF-8")
}) 

#output data

output$im = downloadHandler(
filename = function(){
  paste("Request ",Sys.time(),".csv",sep="")
},
content = function(file){
  write.csv(filedata(),file,row.names = F,fileEncoding = "latin1")
}
)

I understand why Windows users could download correct data. But I don't know why Mac users can also do that, because I know Mac and Linux are both using UTF-8. If I set fileEncoding = "latin1", it should mess up when users are using Mac.

Any ideas why it happens?

Thanks in advance.

来源:https://stackoverflow.com/questions/34936168/r-shiny-download-data-encoding-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!