Reputation: 398
I am working on an application using the shiny package in R.
My application reads in a file (hierarchy.csv) and uses it as a lookup source to create two columns in a datatable. This datatable is (i) rendered using the DT datatables function and (ii) exported it as results.csv
hierarchy.csv contains text with en dashes. When run locally these display correctly both in the rendered table and in results.csv. However, when I publish the app to ShinyApps.io, the en dashes are replaced with < 96 >. (I am using the same browser, Firefox, throughout)
I can get the en dashes to display in the rendered table on shiny.io by replacing them in hierarchy.csv with
"–"
However, I then have this character code rather than en dashes in results.csv.
I suspect I need to specify encoding at some point but I am out of my depth in that regard. How is the ShinyApps.io server set up to deal with special characters?
Any suggestions?
Upvotes: 1
Views: 381
Reputation: 30114
There is an article dedicated to this topic on the shiny website. Basically you need the fileEncoding
argument to specify the encoding explicitly when using read.csv()
or write.csv()
for the sake of portability between Windows (your local machine) and Linux (ShinyApps.io). For example, if you have encoded hierarchy.csv
in UTF-8, you should read it via
read.csv('hierarchy.csv', fileEncoding = 'UTF-8')
Similarly, when writing out data,
write.csv(YOUR_DATA, 'results.csv', fileEncoding = 'UTF-8')
If you download the CSV file written out from shiny, and want to open it locally, you should make sure your application (e.g. LibreOffice) knows its encoding. In your same post in the shiny-discuss mailing list, you said the en-dash was not "displayed" correctly, and it is possible that your application was using a wrong encoding to open the file.
Upvotes: 1