1

I have had this issue for a while. I was working around by not using special characters. However it's high time to solve it.

Issue is very simple: perfectly working app on local run stops working when moved to /srv/shiny-server/

log points excatly at polish sign. Here is a minimal working example:

library(shiny)
library(DT)
library(ggplot2)
df = data.frame(ę = rep(c("group1", "group2"), 50), ć = rnorm(n = 100))

ui <- fluidPage(

    # Application title
    titlePanel("Encoding example"),

    sidebarLayout(
        sidebarPanel(
            ""
        ),

        
        mainPanel(
          plotOutput("Plot")

        )
    )
)

server <- function(input, output) {

    output$Plot <- renderPlot({
      ggplot(df, aes(ę, ć)) +
        geom_boxplot()
        
    })
}

shinyApp(ui = ui, server = server)

Here is the log:

su: ignoring --preserve-environment, it's mutually exclusive with --login
Error in parse(file, keep.source = FALSE, srcfile = src, encoding = enc) :
  /srv/shiny-server/encoding_debugging/app.R:4:17: unexpected input
3: library(ggplot2)
4: df = data.frame(▒^y
                   ^
Error in sourceUTF8(fullpath, envir = new.env(parent = sharedEnv)) :
  Error sourcing /srv/shiny-server/encoding_debugging/app.R
Calls: runApp ... shinyAppDir -> shinyAppDir_appR -> appObj -> func -> sourceUTF8
Execution halted

System settings:

> Sys.getenv('LANG')
[1] "en_US.UTF-8"
> Sys.getlocale()
[1] "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C"

It doesn't allow to have any special characters in variable/column names. How to fix that issue?

I am serving on latest shiny-server on Ubuntu 22.04. All packages are up to date.

Any suggestions?

Best regards Tomasz

Tomasz Wojtas
  • 756
  • 2
  • 6
  • 12
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that can be used to test and verify possible solutions. Did you write the script on the same machine or did you edit it on a Windows machine? What R version are you using? – MrFlick Jun 12 '23 at 20:12
  • Can you share your `Sys.getenv('LANG')`? – divibisan Jun 12 '23 at 20:56
  • Please [edit] your question to provide a [mcve]. Moreover, share your `Sys.getlocale()`… – JosefZ Jun 13 '23 at 10:26
  • @MrFlick - yes, I wrote it on the same machine. – Tomasz Wojtas Jun 13 '23 at 11:54
  • @JosefZ - I added minimal working example and added Sys.getlocale() – Tomasz Wojtas Jun 13 '23 at 11:55
  • @divibisan - I added Sys.getenv('LANG') – Tomasz Wojtas Jun 13 '23 at 11:55
  • Is that the locale on your local machine where this code works, or on the shiny server where it doesn't? Might that be different? Also, try running `utf8ToInt` on the problem characters to make sure they're what you expect. It's possible that while it looks like a "ę", it's actually some other combination of characters that look the same – divibisan Jun 13 '23 at 15:50
  • @divibisan - No - the problem is that on the same machine, when I run on RStudio server this app it works, but when I move it to /srv/shiny-server/ it doesn't. The same machine. It works when I press run app in RStudio server, but it doesn't when it's served by shiny server. – Tomasz Wojtas Jun 13 '23 at 21:05

1 Answers1

0

Finally I found it here: https://github.com/rocker-org/rocker-versioned2/issues/397#issuecomment-1090829840

Solution was very simple - just add "LC_ALL=en_US.UTF-8" to /etc/default/locale

sudo su
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale

Best regards!

Tomasz Wojtas
  • 756
  • 2
  • 6
  • 12