Search code examples
rencodingshinylocaleshinyapps

Locally functioning app encounters an error when deployed to Shinyapps server


I made a shiny app for analyzing a certain type of scientific data. In a nutshell, the program works by analyzing a user-provided .csv input that has gene expression data against known reference samples to identify the type of unknown cells in the experiment.

I can run this shiny app with no problem locally, but when I host it on ShinyApps server, the plot brushing function encounters an error which does not result in a complete crash but it prompts a red error message and fails to output a table summary.

I looked over several SO and RStudio/Shiny threads and saw similar problems occurring due to differences in file encoding that results in breakage on different platforms. Those topics were not helpful for me.

Some of the things I tried can be found in this, this, and this link.

I tried re-saving my server.R and ui.R files and the input .csv file using UTF-8 encoding but didn't work.

The expected outcome is: example

The error looks like this: error

Interestingly I only observe this problem when I brush certain items on the plot. In the example figure here, some of the X-values that break the code upon brushing CD4.CTRL.LN, T.4.LN.BDC, CD8.CTR.LN.

All of the values of x were derived from pre-analysis and they come from a large data frame. I can't see any special characters associated with the problematic data points.

The logs showing the problem is rather cryptic to me:

2019-07-31T20:39:56.688902+00:00 shinyapps[1053041]: Server version: 1.7.6-6
2019-07-31T20:39:56.688904+00:00 shinyapps[1053041]: LANG: en_US.UTF-8
2019-07-31T20:39:56.916208+00:00 shinyapps[1053041]: Using jsonlite for JSON processing
2019-07-31T20:39:56.688945+00:00 shinyapps[1053041]: R version: 3.5.3
2019-07-31T20:39:56.922032+00:00 shinyapps[1053041]: 
2019-07-31T20:39:56.688946+00:00 shinyapps[1053041]: shiny version: 1.3.2
2019-07-31T20:39:56.922034+00:00 shinyapps[1053041]: Starting R with process ID: '23'
2019-07-31T20:39:56.688948+00:00 shinyapps[1053041]: httpuv version: 1.5.1
2019-07-31T20:39:56.688949+00:00 shinyapps[1053041]: rmarkdown version: (none)
2019-07-31T20:39:56.688966+00:00 shinyapps[1053041]: jsonlite version: 1.6
2019-07-31T20:39:56.688985+00:00 shinyapps[1053041]: RJSONIO version: (none)
2019-07-31T20:39:56.689180+00:00 shinyapps[1053041]: Using pandoc at /opt/connect/ext/pandoc2
2019-07-31T20:39:56.689013+00:00 shinyapps[1053041]: htmltools version: 0.3.6
2019-07-31T20:39:56.688965+00:00 shinyapps[1053041]: knitr version: (none)
2019-07-31T20:39:56.950579+00:00 shinyapps[1053041]: 
2019-07-31T20:39:56.950581+00:00 shinyapps[1053041]: Listening on http://127.0.0.1:33950

....

Warning: Error in gsub: input string 1 is invalid in this locale
2019-07-31T20:43:38.699011+00:00 shinyapps[1053041]:   120: gsub
2019-07-31T20:43:38.699022+00:00 shinyapps[1053041]:    93: output$brushtop5
2019-07-31T20:43:38.699014+00:00 shinyapps[1053041]:   119: sanitize
2019-07-31T20:43:38.699051+00:00 shinyapps[1053041]:    13: runApp
2019-07-31T20:43:38.699015+00:00 shinyapps[1053041]:   118: print.xtable
2019-07-31T20:43:38.699053+00:00 shinyapps[1053041]:    12: fn
2019-07-31T20:43:38.699021+00:00 shinyapps[1053041]:    94: origRenderFunc
2019-07-31T20:43:38.699016+00:00 shinyapps[1053041]:   109: transform
2019-07-31T20:43:38.699055+00:00 shinyapps[1053041]:     7: connect$retry
2019-07-31T20:43:38.699017+00:00 shinyapps[1053041]:   108: func
2019-07-31T20:43:38.699056+00:00 shinyapps[1053041]:     6: eval
2019-07-31T20:43:38.699018+00:00 shinyapps[1053041]:   106: f
2019-07-31T20:43:38.699057+00:00 shinyapps[1053041]:     5: eval
2019-07-31T20:43:38.699019+00:00 shinyapps[1053041]:   105: Reduce
2019-07-31T20:43:38.699019+00:00 shinyapps[1053041]:    96: do
2019-07-31T20:43:38.699020+00:00 shinyapps[1053041]:    95: hybrid_chain
2019-07-31T20:43:39.087982+00:00 shinyapps[1053041]:   118: print.xtable
2019-07-31T20:43:39.087989+00:00 shinyapps[1053041]:    94: origRenderFunc
2019-07-31T20:43:39.087990+00:00 shinyapps[1053041]:    93: output$brushtop5
2019-07-31T20:43:39.087991+00:00 shinyapps[1053041]:    13: runApp
2019-07-31T20:43:39.087992+00:00 shinyapps[1053041]:    12: fn
2019-07-31T20:43:39.087984+00:00 shinyapps[1053041]:   108: func
2019-07-31T20:43:39.087994+00:00 shinyapps[1053041]:     7: connect$retry
2019-07-31T20:43:39.087986+00:00 shinyapps[1053041]:   105: Reduce
2019-07-31T20:43:39.088031+00:00 shinyapps[1053041]:     6: eval
2019-07-31T20:43:39.087987+00:00 shinyapps[1053041]:    96: do
2019-07-31T20:43:39.088034+00:00 shinyapps[1053041]:     5: eval


Any ideas how to solve this issue? Thanks!


Solution

  • I figured the problem out. Turns out I had a non-ASCII character ( ï ) in one of the columns of the data frame.

    I noticed this while I was making a reprex for this question. I didn't realize this issue earlier since these special characters were in one of the .rds files used by the app. While these data frames were being saved, RStudio encoded it accordingly to show things right but this encoding caused problems on the Shiny server side since it requires all its components to be UTF-8 encoded.

    I guess I wouldn't have had this problem if I made sure that the data frame had no special characters early on or used UTF-8 encoding which would overwrite these characters. I will mark this question answered, but feel free to add comments and if you would have another solution.