Shiny: utf-8 display issue in rendering functions

Created on 19 Apr 2017  Â·  5Comments  Â·  Source: rstudio/shiny

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

Intermediate Medium Medium Type

Most helpful comment

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

All 5 comments

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.

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

@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)

Yes, using renderUI instead does solve this issue.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

beginner984 picture beginner984  Â·  4Comments

hudon picture hudon  Â·  4Comments

howardcoleman picture howardcoleman  Â·  5Comments

kiendang picture kiendang  Â·  3Comments

HarlanH picture HarlanH  Â·  3Comments