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
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.
Most helpful comment
I'm reopening this because it is a bug that should be addressed.