rstudio可以很好地显示汉字,但不能 问题描述
代码如下:rstudio可以很好地显示汉字,但不能 问题描述,r,shiny,R,Shiny,代码如下: library(shiny) library(Ruchardet) ui <- fluidPage( # Application title titlePanel("中文测试"), textOutput("test") ) server <- function(input, output) { output$test <- renderText({ # detectFileEncoding: detect the encoding
library(shiny)
library(Ruchardet)
ui <- fluidPage(
# Application title
titlePanel("中文测试"),
textOutput("test")
)
server <- function(input, output) {
output$test <- renderText({
# detectFileEncoding: detect the encoding of file
paste(detectFileEncoding("line.txt"),
readLines("line.txt"),
"人")
})
}
# Run the application
shinyApp(ui = ui, server = server)
附加信息
它运行在一个docker容器中,中文字体已经安装在apt get install fonts wqy zenhei中。
以下是会话信息:
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Ruchardet_0.0-3 shiny_1.0.3
loaded via a namespace (and not attached):
[1] compiler_3.4.0 R6_2.2.2 htmltools_0.3.6 tools_3.4.0 Rcpp_0.12.11
[6] jsonlite_1.5 digest_0.6.12 xtable_1.8-2 httpuv_1.3.3 mime_0.5
在Firefox上,这看起来很适合我。您使用的是什么web浏览器?检查网页内容,查看如何返回汉字。您的web浏览器可能与RStudio的web浏览器窗口的解释不同。原因不是浏览器。谢谢您的回复。我刚找到它。这是语言环境。我通过在Shining server中获取Sys.getlocale的结果找到了它。它没有rstudio中的en_US.UTF-8语言环境。因此,我将Sys.setlocalecategory=LC_ALL,locale=en_US.UTF-8添加到Rprofile.site文件中。现在没事了。
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Ruchardet_0.0-3 shiny_1.0.3
loaded via a namespace (and not attached):
[1] compiler_3.4.0 R6_2.2.2 htmltools_0.3.6 tools_3.4.0 Rcpp_0.12.11
[6] jsonlite_1.5 digest_0.6.12 xtable_1.8-2 httpuv_1.3.3 mime_0.5