why my unicode characters doesn't render correctly under shiny >0.10.1?

瀏覽次數:2,439 次
跳到第一則未讀訊息

Nelson Muntz

未讀,
2015年1月5日 晚上10:01:382015/1/5
收件者:shiny-...@googlegroups.com
After several times failure, I just copied official example (http://shiny.rstudio.com/gallery/unicode-characters.html) to test in my shiny environment. But it doesn't work neither.

I saved the code in utf-8 encoding using Rstudio in Windows. And in Ubuntu I checked file encoding using bash command "file".

I test official example both under Windows 7(R 3.1.0; Rstudio 0.98.1091; shiny 0.9.1, 0.10.0, 0.10.1, 0.10.2.2) and Ubuntu 14.04(R 3.1.0; shiny 0.9.1, 0.10.0, 0.10.1, 0.10.2.2). 
1. Under shiny <=0.10.0, chinese character label from ui.R work well but from server.R show messy. 
2. Under shiny >0.10.0, all chinese character label show messy under Windows 7 and the application exited during initialization under Ubuntu.(please see attachment image)

Here is some information in Rstudio (Windows 7; shiny 0.10.1):

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_0.10.1

loaded via a namespace (and not attached):
[1] bitops_1.0-6    caTools_1.17.1  digest_0.6.8    htmltools_0.2.6 httpuv_1.3.2    Rcpp_0.11.3    
[7] RJSONIO_1.3-0   tools_3.1.0     xtable_1.7-4 


> shiny::runApp('unicode')
Loading required package: shiny
Warning in checkEncoding(file) :
  The file "D:\Dropbox\Rsource\learnShiny\PC_calc\unicode/global.R" is not encoded in UTF-8. Please convert its encoding to UTF-8 (e.g. use the menu `File -> Save with Encoding` in RStudio). See http://shiny.rstudio.com/articles/unicode.html for more info. Falling back to the encoding "native.enc".

Warning in checkEncoding(file) :
  The file "D:\Dropbox\Rsource\learnShiny\PC_calc\unicode/ui.R" is not encoded in UTF-8. Please convert its encoding to UTF-8 (e.g. use the menu `File -> Save with Encoding` in RStudio). See http://shiny.rstudio.com/articles/unicode.html for more info. Falling back to the encoding "native.enc".
Error in fromJSON(content, handler, default.size, depth, allowComments,  : 
  invalid JSON input 


Could anyone help me to solve my problem, please?
ubuntu.shiny.0.10.1.jpg
windows.shiny.0.10.1.jpg

Yihui Xie

未讀,
2015年1月5日 晚上11:01:062015/1/5
收件者:Nelson Muntz、shiny-discuss
There could be multiple issues in this post:

First, please do not try shiny < 0.10.1. That will only waste your
time. The article http://shiny.rstudio.com/articles/unicode.html
stated clearly that the support was only available since shiny 0.10.1.
The next time if you want to try anything, please start from the
latest CRAN release. If that does not work, try
devtools::install_github('rstudio/shiny') to see if the problem still
exists; if it does, it is time to report to us. We certainly
appreciate it if you test multiple previous versions, but sometimes it
is probably not worth it.

Your Windows locale is English_United States.1252, which means you are
unlikely to be able to run that example by definition, since the
example uses Simplified Chinese characters. To run it, you may have to
change your system locale to Simplified Chinese (go to the Control
Panel -> Region and Language -> find the button to change the locale;
you can keep the display language as English, unless you can read
Chinese).

You said you "copied" the example, and copying text does not guarantee
what its encoding will be under Windows. You should download the
example from https://github.com/rstudio/shiny-examples You can either
clone the GIT repo, or just download it if you do not know GIT:
https://github.com/rstudio/shiny-examples/archive/master.zip Then
unzip it, and run the example 022. This guarantees you will not change
the original encoding by accident. If your OS does not support Chinese
characters, it will not work even if you save the file as UTF-8.

Once you are in a Chinese locale, makes sure the file encoding is
UTF-8, **and** have Chinese fonts available (to show Chinese
characters in the plot), you should be able to run the example under
Windows.

For Ubuntu, the encoding is not an issue (the default locale is often
base on UTF-8). I'm surprised that the example did not work. I suspect
you copied the files from Windows, instead of using our original
example files in the Github repo.

Regards,
Yihui

Nelson Muntz

未讀,
2015年1月6日 凌晨2:59:502015/1/6
收件者:shiny-...@googlegroups.com、nelso...@gmail.com
Hey Yihui,

It works! Thank you!

As you suggest, I changed the system locale to Simplified Chinese in Windows. Then all chinese character display correctly.
In Ubuntu, I update shiny-server from version 1.1.0.1000 to version 1.2.3.368 and update shiny using "devtools::install_github("rstudio/shiny")". Then the application works well.

Yihui Xie

未讀,
2015年1月6日 上午11:09:172015/1/6
收件者:Nelson Muntz、shiny-discuss
Perfect. Glad to know the "if-not-working-then-upgrade" strategy worked :)

Regards,
Yihui

Yong Jiang

未讀,
2015年2月20日 中午12:59:252015/2/20
收件者:shiny-...@googlegroups.com、nelso...@gmail.com
Hi, Yihui,

I am seeing another issue while trying to run your example on Win 7. The error message tells the file is not saved with UTF-8 encoding. But I do save it as UTF-8 by selecting File/Save with encoding and then select UTF-8 in RStudio. My system locale is also changed to simplified Chinese.
Below is the error message:

Warning in checkEncoding(desc) :
The file "C:/Users/jiang_y/Documents/R/Proj_Stock/shiny-examples/022-unicode-chinese/DESCRIPTION" is not encoded in UTF-8. Please convert its encoding to UTF-8 (e.g. use the menu `File -> Save with Encoding` in RStudio). See http://shiny.rstudio.com/articles/unicode.html for more info. Falling back to the encoding "native.enc".

I cloned the example from Github https://github.com/rstudio/shiny-examples. The error was reported for every file in  "022-unicode-chinese" folder.

Please advise how I can fix it. Thank you.

Happy Chinese New Year !

Regards,
Yong 

Yihui Xie

未讀,
2015年3月5日 上午9:03:262015/3/5
收件者:Yong Jiang、shiny-discuss
Hmm... That is weird. What is your sessionInfo() after library(shiny)?

Regards,
Yihui

Yong Jiang

未讀,
2015年3月5日 下午2:50:122015/3/5
收件者:Yihui Xie、shiny-discuss
Hi, Yihui,

This is the sessionInfo():

Inline image 1

It is weird the locale info returned above is still "English", below is the one from control panel.

Inline image 2\

Regards,
Yong

Yong Jiang

未讀,
2015年3月5日 晚上7:10:072015/3/5
收件者:Yihui Xie、shiny-discuss
Hi, Yihui,

I fixed the issue, just need to set both properties (I missed the first one):
  1. Control Panel -> Region and Language -> Formats -> Chinese (Simplified, PRC)
  2. Control Panel -> Region and Language -> Administrative -> Change System Locale... -> Chinese (Simplified, PRC)
Thank you very much!

Regards,
Yong

Yihui Xie

未讀,
2015年3月5日 晚上8:51:182015/3/5
收件者:Yong Jiang、shiny-discuss
Perfect. Thanks for sharing the solution!

Regards,
Yihui

On Thu, Mar 5, 2015 at 6:09 PM, Yong Jiang <yong.j...@gmail.com> wrote:
>
> Hi, Yihui,
>
> I fixed the issue, just need to set both properties (I missed the first one):
>
> Control Panel -> Region and Language -> Formats -> Chinese (Simplified, PRC)
> Control Panel -> Region and Language -> Administrative -> Change System Locale... -> Chinese (Simplified, PRC)
>
> Thank you very much!
>
> Regards,
> Yong
>
>
> On Thu, Mar 5, 2015 at 11:49 AM, Yong Jiang <yong.j...@gmail.com> wrote:
>>
>> Hi, Yihui,
>>
>> This is the sessionInfo():
>>
>>
>>
>> It is weird the locale info returned above is still "English", below is the one from control panel.
>>
>> \

Li Wang

未讀,
2016年5月24日 下午2:50:432016/5/24
收件者:Shiny - Web Framework for R、yong.j...@gmail.com
Hi Yihui,

I tried to add Japanese hiragana to the app but cannot render hiragana symbols as output text. Would you kindly help?

The session info:

R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] shiny_0.13.0

loaded via a namespace (and not attached):
 [1] R6_2.1.1         htmltools_0.3    tools_3.2.2     
 [4] rstudioapi_0.3.1 Rcpp_0.12.1      jsonlite_0.9.17 
 [7] digest_0.6.8     xtable_1.7-4     httpuv_1.3.3    
[10] mime_0.4        

The whole app:

library(shiny)

hiragana <- c("あ","か","が","さ")
romaji <- c("a", "ka", "ga", "sa")
index <- floor(runif(1,1,5))


ui <- shinyUI(fluidPage(

  # Application title
  titlePanel("Hiragana ひらがな"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      textInput("answer", "answer", value = "")
    ),

    mainPanel(
      textOutput("isCorrect"),
      textOutput("correctAns")
    )
  )
))


server <- shinyServer(function(input, output) {
  
  output$correctAns <- renderText(hiragana[index])
    
  
  output$isCorrect <- reactive({
    if (input$answer == romaji[index])
    {result <- "TRUE"}
    else 
    {result <- "FALSE"}
    return(result)
  })
  
  
})

Screenshot:

Thanks.

Best,
Li Wang


# Run the application 
shinyApp(ui = ui, server = server)
回覆所有人
回覆作者
轉寄
0 則新訊息