unicode inequalities (u2264 and u2265) not working on windows

152 views
Skip to first unread message

Garth Tarr

unread,
Sep 19, 2015, 7:48:14 PM9/19/15
to Shiny - Web Framework for R
Hi,

I've done some looking around and found that there are issues with unicode + shiny + windows.  Sometimes it appears this can be fixed by changing the locale.

Just wondering if anyone has tried to include "less than or equal to" and "greater than or equal to" signs in a shiny app that needs to run on a windows computer.

require(shiny)
app <- shinyApp(
  ui = fluidPage(
    uiOutput("bin_prob_k"),
    uiOutput("bin_prob_inequality"),
    uiOutput("bin_prob_out"),
    plotOutput("pmf")
  ),
  server = function(input, output) {
    
    output$bin_prob_k = renderUI({
      numericInput("binom4_k", label = "Number of successes (k)", value = 3,
                   step = 1, min = 0, max = 10)
    })
    
    bin_choices = reactive({
      nms = paste("P(X",c("=","\u2264","<","\u2265",">"),input$binom4_k,")",sep="")
      return(nms)
    })
    
    output$bin_prob_inequality = renderUI({
      selectInput("bin_prob_type", label = "Inequality type", choices = bin_choices())
    })
    
    output$pmf <- renderPlot({
      n=10
      prob = 0.4
      probs = dbinom(0:n, size=n, prob=prob)
      mtext(input$bin_prob_type, side = 3, col = "red", cex = 1.2)
    })
    
    output$bin_prob_out = renderUI({
      withMathJax(paste0("\\(",input$bin_prob_type,"\\)",sep=""))
    })
  }
)


The above app works perfectly on a mac or linux machine but windows machines ignore the unicode characters.

Any suggestions?





Yihui Xie

unread,
Sep 21, 2015, 4:02:23 PM9/21/15
to Garth Tarr, Shiny - Web Framework for R
Yes, Unicode characters can be tied to the locale on Windows. Could
you try the development version of htmltools?

if (!require('devtools')) install.packages('devtools')
devtools::install_github('rstudio/htmltools')

Then restart R and reload you app. BTW, what is your locale anyway?
sessionInfo()?

Regards,
Yihui

Garth Tarr

unread,
Sep 21, 2015, 5:41:17 PM9/21/15
to Shiny - Web Framework for R, garth...@gmail.com
Thanks for the reply Yihui.

After your suggestion I tried the latest htmltools package but that did not solve the problem (same output as above).

On Windows (where the problem is) my sessionInfo:

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

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    
[5] datasets  methods   base     

other attached packages:
[1] shiny_0.12.2.9003

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

And on my mac (which has no problems with the unicode characters):

> sessionInfo()
R Under development (unstable) (2015-09-07 r69315)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

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

other attached packages:
[1] shiny_0.12.2.9003

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

Yihui Xie

unread,
Sep 21, 2015, 6:25:04 PM9/21/15
to Garth Tarr, Shiny - Web Framework for R
I just tested it, and indeed it is related to the system locale. Your
app works if I change the locale to Simplified Chinese, but does not
work if I use the English locale. I'm not quite sure if it is a bug of
shiny or base R...

Regards,
Yihui

Garth Tarr

unread,
Sep 21, 2015, 9:11:21 PM9/21/15
to Shiny - Web Framework for R, garth...@gmail.com
Very interesting, thanks for the fix Yihui!

For completeness if anyone else is watching, on my Windows machine to my shiny app code I added:

Sys.setlocale("LC_CTYPE", "Chinese")

and then things ran perfectly.  

I have not (yet) found any complications when this change was also made with my larger app (as opposed to this MWE).

It's a strange bug, but thankfully relatively straightforward to work around it.

Thanks again Yihui!

Yihui Xie

unread,
Sep 21, 2015, 9:19:54 PM9/21/15
to Garth Tarr, Shiny - Web Framework for R
Interesting. I'm a little surprised that you are able to set the
locale to Chinese :)

My gut feeling is that this is a bug in shiny, although the bug was
actually caused by a bug in base R (which was fixed the day before
yesterday in the development version of R). I need to revisit the
issue of multibyte characters on Windows after the next version of R
is released. Do you mind filing an issue to
https://github.com/rstudio/shiny/issues? (You will be automatically
notified when it is fixed) Thanks!

Regards,
Yihui
> --
> You received this message because you are subscribed to the Google Groups
> "Shiny - Web Framework for R" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shiny-discus...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/shiny-discuss/91df27c9-1852-4fe6-a808-44725ea94d0c%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages