rstudio / shiny-server

Host Shiny applications over the web.
https://rstudio.com/shiny/server
Other
718 stars 288 forks source link

OSX shiny server (but not standalone) sends NA for unicode #16

Open alexbbrown opened 11 years ago

alexbbrown commented 11 years ago

I installed node shiny server (first from npm, then from download of head from here) on OSX server 10.8.3 and after a number of successful fetches and a lot of shiny UI coming up, the application jams up when the web client gets a message consisting solely of "NA". This does not happen for standalone shiny (runApp())

The issue is the transmission of unicode characters in renderTable.

It's not appearing in the shiny trace - must be coming from the node server

Client (safari or chrome) says:

[Error] SyntaxError: JSON Parse error: Unexpected identifier "NA" dispatchMessage (shiny.js, line 704) onmessage (shiny.js, line 471) dispatchEvent (sockjs-0.3.min.js, line 27) _dispatchMessage (sockjs-0.3.min.js, line 27) _didMessage (sockjs-0.3.min.js, line 27) onmessage (sockjs-0.3.min.js, line 27)

To replicate:

==> Server.R <== require(shiny) greeting<-scan("greeting","") shinyServer(function(input,output){ output$greeting<-renderTable({ data.frame(greeting) }) })

==> UI.R <== require(shiny) shinyUI(tableOutput("greeting"))

==> greeting <== Welcome, the water is 50ºC

trestletech commented 11 years ago

Did you install from npm or from the source?

Did you notice the performance of your machine degrading? I ask because we recently released a patch (not yet on npm), before which the R processes wouldn't properly shut down on OSX. So if you were soaking the application for a long enough time, you could have ended up with a few hundred idle R processes eating up memory and causing some instability until you shut down the parent process.

If that doesn't sound related, then we can do some work to see if we can replicate.

alexbbrown commented 11 years ago

Have added simple test case to main body.

alexbbrown commented 11 years ago

Looks like it's an encoding issue. That's pretty much my problem, but the shiny server problem here is the response of the server to the encoding problem - it sends a poison message to the browser (JSON NA), which silently eats it and locks up shiny UI.

Note that if I explicitly set the encoding to UTF-8 (which I should) when I load the file, shiny server no longer locks up the web page, but it transforms the encoding of °C into <u+00b0>C </u+00b0>, which is just nonsense (it's not HTML!). Stand alone shiny does not do this.

alexbbrown commented 11 years ago

oops, github has eaten my explanation.
screen shot 2013-06-19 at 10 39 42 am

jcheng5 commented 11 years ago

Thanks, we're on it!

jcheng5 commented 11 years ago

Curiouser and curiouser. If you launch a local Shiny process the same way that shiny-server does:

sudo su - shiny -c "cd /var/shiny-server/www/bad; R -e 'shiny::runApp()'"

then the problem repros, even without Shiny Server in the loop at all.

jcheng5 commented 11 years ago

This works (LANG environment variable added):

sudo su - shiny -c "cd /var/shiny-server/www/bad; LANG=en_US.UTF-8 R -e 'shiny::runApp()'"

jcheng5 commented 11 years ago

OK, it's what iconv does when it can't translate a string.

sudo su - shiny -c "cd /var/shiny-server/www/bad; R -e \"iconv(readLines('greeting', warn=F), to='UTF-8')\""

I'll have to think a bit on how to fix this...

alexbbrown commented 11 years ago

so it's not just tables - textOutput explodes on unicode input, too.

jcheng5 commented 11 years ago

Yes, it pretty much doesn't matter what it is.

You can work around this for now by declaring this option in server.R:

options(shiny.transcode.json = FALSE)

alexbbrown commented 11 years ago

thanks, quick work!