Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding in Shiny

I'm working with RStudio Version 0.98.507. Short Info about initial working instruments:

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

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

other attached packages:
[1] shinyapps_0.3.53 RJSONIO_1.2-0.2  shiny_0.9.1.9013

loaded via a namespace (and not attached):
 [1] bitops_1.0-6    Cairo_1.5-5     caTools_1.17    digest_0.6.4   
 [5] htmltools_0.2.4 httpuv_1.3.0    Rcpp_0.11.1     RCurl_1.95-4.1 
 [9] shinysky_0.1.2  tools_3.1.0     xtable_1.7-3   

I have a problem by deploying my shiny app on the shiny server. The problem was at some point solved, but after it appears again. Now I cannot fix it any more. My problem are the german letters in helpers.R. Unfortunately, I cannot avoid using them. I'm sourcing my help scrpits helpers.R into server.R like it is shown and taught in Shiny Tutorial. All my R-scripts are carefully saved under UTF-8 format. I cannot use the command

options(encoding="UTF-8")

because after executing it, the command deployApp("app") doesn't work. I set location using

Sys.setlocale(category = "LC_ALL", locale = "German")

It also doesn't work. I cannot understand, why the letters in mainPanel and sidebarLayout are readable, but those from helpers.R not. Can someone help me to solve this paradox?

EXAMPLE

ui.R

library(shiny)

shinyUI(fluidPage(withMathJax(),
                  titlePanel("Währung"),

                  sidebarLayout(position="right",
                                sidebarPanel(
                                        h5("Bedienfenster"),
                                        sliderInput('x', 'x axis',
                                                    value=50, min=3, max=150, step=1,)
                                ),

                                mainPanel(
                                        plotOutput("Plot")
                                )
                  )
))  

server.R

shinyServer(function(input, output){
        output$Plot <- renderPlot({
               x <- rnorm(input$x)
               hist(x, main="", xlab="", ylab="")
               title(main="Schätzgerade", xlab="Währung", ylab="Dichte")
        })
})

After deploying I get following app.

like image 315
And_R Avatar asked Jun 21 '14 09:06

And_R


People also ask

Why is R Shiny so slow?

There are many reasons why a shiny app runs slower than expected. The most common reason is the Shiny app code has not been optimized. You can use the profvis package to help you understand how R spends its time. You also might want to make sure your server is large enough to host your apps.

What style of programming is Shiny?

Shiny is an R package that allows you to easily create rich, interactive web apps. Shiny allows you to take your work in R and expose it via a web browser so that anyone can use it.

How do I make text Shiny in R?

Supply a style attribute to change the format of the entire paragraph.", style = "font-family: 'times'; font-si16pt"), strong("strong() makes bold text."), em("em() creates italicized (i.e, emphasized) text."), br(), code("code displays your text similar to computer code"), div("div creates segments of text with a ...

Is R Shiny difficult?

Along with Shiny elements, you can use HTML elements to stylize your content in your application. In my opinion, R Shiny is very easy to learn despite how powerful the tool is. If you're working on a side project or looking to add something to your portfolio, I highly recommend trying it out.


2 Answers

As a workaround (which I haven't tested), have you tried using escaped Unicode characters, such as "W\u00E4hrung" instead of "Währung"? You can can find details of how to do this with ?Quotes, and there is a list of Unicode characters at http://en.wikipedia.org/wiki/List_of_Unicode_characters.

like image 198
James Trimble Avatar answered Sep 22 '22 12:09

James Trimble


What work for me is to change the encoding of the file (in Rstudio File>Reopen open with encoding) and set encoding:

  • UTF-8 for ui.R
  • WINDOWS-1252 for server.R and global.R

I do not know the reason but it made the trick for me.

like image 43
pau.ferrer Avatar answered Sep 20 '22 12:09

pau.ferrer