Shiny local deployment error : input string 1 is invalid UTF-8
Asked Answered
D

1

9

I am surprised to see a sudden error where my ShinyApp stopped working with an unknown error saying 'input string 1 is invalid UTF-8'. Even on yesterday, that App was working perfectly, however, stopped all sudden.

Below is the description of the error when I run runApp()

> runApp()

Listening on http://127.0.0.1:3726
Warning: Error in sub: input string 1 is invalid UTF-8
Stack trace (innermost first):
    1: runApp
Error : input string 1 is invalid UTF-8

My session info :

> library(shiny); sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

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

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

other attached packages:
[1] shiny_1.0.5

loaded via a namespace (and not attached):
[1] compiler_3.4.1  R6_2.2.2        htmltools_0.3.6 Rcpp_0.12.12   
[5] digest_0.6.12   xtable_1.8-2    httpuv_1.3.5    mime_0.5 

Have someone faced with similar error? Appreciate for any pointer on how to fix this error. I searched over net for a while for its solution, however didnt find any relevant.

Thanks for your time.

Thanks,

Daybreak answered 5/9, 2017 at 20:30 Comment(1)
I had the same problem and solved it by replacing non UTF-8 characters in my data. validUTF8() helped me identify non UTF-8 characters.Gehring
N
5

Are you using includeHTML by any chance?

I've had this issue when saving Microsoft Publisher documents as .htm files then slapping them into an app.

It looks like includeHTML enforces 'UTF-8' encoding:

> includeHTML
function (path) {
  lines <- readLines(path, warn = FALSE, encoding = "UTF-8")
  return(HTML(paste8(lines, collapse = "\\r\\n")))
}

However my Windows 10 system default is 'ISO-8859-1'.

In Rstudio you can do File > Save With Encoding > UTF-8 and everything seems to work. Otherwise you could override the includeHTML function to allow the encoding argument of readLines to be set.

Nevillenevin answered 21/9, 2017 at 4:38 Comment(1)
Hi Hayden, I later observed that in my Shiny app, there was a peculiar string which was causing that error. I removed that particular string and replaced it with something more meaningful. Now it is working fine. Anyway thanks for your pointer. Regards,Daybreak

© 2022 - 2024 — McMap. All rights reserved.