Plotly tooltip showing unicode character instead of letters in shiny server (R - r

I have a shiny application running in a shiny server that started giving errors for all accented characters today (it was working with no errors until yesterday night).
I realized that all files seemed to be sourced using other types of encoding than utf-8. Thus, I tried forcing it using source('file.R', encoding='utf-8') , but this gives an error and the application doesn't run.
Since I could not find the reason to why this was happening, I changed all characters to their unicode format (\u00xx) and used the enc2utf8 where needed.
After doing this, most of the application seemed to be working fine. The only problem that I am having now, is that the tooltip of my plotly charts started showing the unicode value instead of the character as shown in the image below. I tried not using the enc2utf8 on those dataframes but it also showed the characters with errors. For example, it should be Último but it appears <c3><9a>ltimo when not using the enc2utf8.
How do I solve this problem? Is there a better way to force the files to be read in utf-8 instead of wharever encoding it is being read?
Extra information:
In RStudio I am saving all files as UTF-8 by default, so I assumed the encoding should not be an issue
In my local machine (windows) the application runs just fine and the plots are shown perfectly. The errors only occur on the server that runs in a linux machine

Related

Saving an R-Script results in empty file

I have recently started using R for uni. I want to save my code using either save as or ctrl+s. However, the saved file is empty more often than not. For some reason, the files save normally on a few occasions. However, they also became empty after saving changes to the script.
I couldn't find any solution for the problem, neither here nor anywhere else.
I am using RStudio installed via Anaconda on an Windows 10 x64 Notebook, if that helps.
Thanks a lot for the responses! I'd be glad to provide more details if needed!
This is what the saved files look like from File Explorer:
I just meet the exactly same problem. I solved it by checking and changing RStudio -> File -> "Save as Encoding" from "ISO-8859-1 (System default)" to "UTF-8", then the file was saved. I'm trying to recover my previous 0kb files...
i couldn't reproduce the error but i also don't like to use the anaconda environment.
if the problem is saving the text file than may i suggest to do just that and save the code in a regular .txt file?
if this is not an option you can try to find out what happens if you save the r studio code on a different drive (or usb/flash drive)
###########################################################
EDIT 14.07.2022
Interestingly enough, just today (14.07.2022) I had the same problem. After installing R 4.2.1 everything worked fine until I changed the encoding (from utf-8 to windows 1252), at which point all the files in my project were overwritten and are now empty. Changing back to an older version of R (4.1.3) allowed me to display/save/use all scripts again (from backups).
Using the answer provided by #Shidan it is possible to open the data in R-4.2.1 as well.
This problem does not seem to be connected to Anaconda but an encoding issue between Rstudio and any R distribution above (and including) 4.2.

Render japanese font in ggplot

I am creating a R shiny web app, which I have to publish in Japanese. The application plots many graphs, mainly using ggplot2.
After I run my application on my local machine, the browser renders all Japanese fonts in & outside ggplot correctly. However, when I upload it in shiny-apps, ggplot does not render Japanese text in Japanese characters.
I have already tried few tricks on stack overflow without any luck.
I am using a Windows machine, and have changed my local RStudio settings to utf8.
Shinyapps is by default utf8

R studio code execution error (file name conversion error)

Suddenly above error messages come when I type a single character on my R studio script window. What is the reason? And Is there somebody tell me how to fix it?
Usually this problem is associated with using non-English characters in the directory name (for packages, working directories etc.). In your case it is connected to auto-completion basename(.rs.listIndexedPackages()) - hence when you are typing a character an error is thrown. See the similar problem Issue loading data of “file name conversion problem - name too long?”.
Generally it advisable not to use non-English characters for directory name. And if the above mentioned error was thrown, you would either clear the RStudio environment by deleting temporary RStudio files or rename related directories from Korean to English.

Chinese character encoding with differenct operation systems/languages

I am having trouble read my csv file containing simplified Chinese character into my r. I have tried the encoding=utf-8,gb18130,gb2130 etc. The Chinese character could be not displayed.
I also tried change the encoding by excel to utf8 csv, no luck.
I also
tried using Chinese windows and set the locale to China. No luck.
After I change to Chinese windows. The excel can open my csv (English
windows cannot open it correctly). The r studio can open it in the
View() but the R console console could not read my csv even if I
reinstall the r as Chinese version.
I tried the Ubuntu, Ubuntu could not even read my csv at all. At least in Windows, the R studio can read my data well.
I tried google sheet. But my file is so big that Google sheet would
not even open it
I tired Cals in Ubuntu and convert it GB* since GB is
working fine in Windows R studio. No luck. And it takes more than 10
minutes to convert my 200Mb-750Mb data to gb18013
The Ubuntu use UTF-8 as default Chinese Encoding. So you should encode it as UTF-8 instead GB18130 or other GB starting encoding.
(1) Download Open Office (free and fast to install, have have higher
file size than Cals in Ubuntu).
(2) Detect your CSV encoding. Simply open your csv using Open office and choose an encoding method that display your Chinese character.
(3) Save your csv to the correct encoding according to your
operation system. Default Windows encoding is GBK for Chinese and Ubuntu is UTF8.
This should solve your file size problem and encoding problem. You do not even have to force the encoding. Normal read.csv would work.

Problems working with Rgui in Win7.64-bit...gibberish non-english characters

I have some problems with the execution of R GUI in Windows 7/64-bit. It appears gibberish while running R terminal sounds ok. here are the pictures of the two. I searched the web but I have no clue.

Resources