Kathi
Kathi

Reputation: 99

How to display Chinese charatcers in RMarkdown Shiny

I would like to use RMarkdown and Shiny with Chinese characters. Any ideas why the below won't work?

-

--
title: "Untitled"
author: "test"
date: "26 January 2018"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
Sys.setlocale(category = "LC_ALL", locale = "chs")
a<- "你"

```

```{r}
print(a)
```

Output

Upvotes: 1

Views: 1542

Answers (1)

GyD
GyD

Reputation: 4072

Are you using RStudio on Windows? Unfortunately character encoding is hell on Windows...

The only way I could get this to work on Windows is a workaround:

1, It seems that setting locale via Sys.setlocale doesn't work properly. Instead set the locale inside .Rprofile with file.edit('.Rprofile').

Content of .Rprofile

Sys.setlocale(category = "LC_ALL", locale = "chs")

2, Save your Markdown file with encoding in RStudio (I chose x_Chinese-Eten) Save with encoding

3, After completing these two steps, the output is still NA... but if you use renderPrint instead of print it magically works.

renderPrint

Upvotes: 2

Related Questions