Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf-8 display issue in rendering functions #1671

Open
jiayi9 opened this issue Apr 19, 2017 · 7 comments
Open

utf-8 display issue in rendering functions #1671

jiayi9 opened this issue Apr 19, 2017 · 7 comments

Comments

@jiayi9
Copy link

jiayi9 commented Apr 19, 2017

Saving all files in UTF-8 encoding does make all UTF-8 characters in the ui.R display properly. But the characters in all rendering functions still don't get displayed correctly.

library(shiny)

server <- function(input, session, output) {
  output$UTF8_text = renderText({
    "中文"
  })
}

ui <- fluidPage(
  p("中文"),
  textOutput("UTF8_text")
)

shinyApp(ui = ui, server = server)

The two Chinese characters is displayed as <U+4E2D> and is displayed as <U+6587>.
Please see below.
http://stackoverflow.com/questions/43485436/r-shiny-display-utf-8-characters-in-render-functions

@wch
Copy link
Collaborator

wch commented Apr 19, 2017

I'm able to reproduce this problem in Windows when I save that to a file (as UTF-8) and then call runApp() on it. I wonder if it's an issue with how jsonlite is converting it.

@wch
Copy link
Collaborator

wch commented Apr 19, 2017

The problem is in renderText: it calls capture.output(cat(value)), and that seems to not work correctly with these characters in Windows.

> cat("中文")
中文
> utils::capture.output(cat("中文"))
[1] "<U+4E2D><U+6587>"

This is the code in question:
https://github.com/rstudio/shiny/blob/f8f2acf/R/shinywrappers.R#L318

@wch
Copy link
Collaborator

wch commented Apr 19, 2017

@jiayi9 One workaround is to use renderUI, which doesn't have this problem:

library(shiny)

server <- function(input, session, output) {
  output$UTF8_text = renderUI({
    "中文"
  })
}

ui <- fluidPage(
  p("中文"),
  uiOutput("UTF8_text")
)

shinyApp(ui = ui, server = server)

@jiayi9
Copy link
Author

jiayi9 commented Apr 20, 2017

Yes, using renderUI instead does solve this issue.

@jiayi9 jiayi9 closed this as completed Apr 20, 2017
@wch
Copy link
Collaborator

wch commented Apr 20, 2017

I'm reopening this because it is a bug that should be addressed.

@marton-balazs-kovacs
Copy link

Could you find a solution to this issue? I am using renderText with htmlOutput and it is still not working properly for me.

@pitakakariki
Copy link

Hi, I just ran into this trying to get macrons to work properly in Māori. Thanks for the renderUI/outputUI workaround, worked for me. Hopefully Windows 11 supports Unicode so we don't have to worry about stuff like this anymore :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants