works locally but server says: Uncaught SyntaxError: Unexpected token N

1,190 views
Skip to first unread message

Jan Stanstrup

unread,
Jun 12, 2014, 7:36:05 AM6/12/14
to shiny-...@googlegroups.com
I am working on an app where the user uploads a csv file, data is extracted and written to a mongodb and for testing the data is read back from the db and shown.
This works fine locally but on the server something happens after the data is read back from the db. The renderUI I am using seems to never be created and the console gives the following error:

  1. Uncaught SyntaxError: Unexpected token N shiny.js:812
    1. dispatchMessageshiny.js:812
    2. socket.onmessageshiny.js:539
    3. d.dispatchEventsockjs-0.3.min.js:27
    4. y._dispatchMessagesockjs-0.3.min.js:27
    5. d.dispatchEventsockjs-0.3.min.js:27
    6. g.xhr.onreadystatechange


The app can be found here: https://github.com/stanstrup/shiny.apps/tree/master/apps/retdb and a sample input file has been attached.

Any idea what is going on?
I am using shiny package shiny_0.9.1.9015 and server shiny-server-1.1.0.10000-amd64 on ubuntu.
I tried to install the server from github but it appears that my apache redirection of port 3838 to a subfolder stopped working if I did that (other apps stopped working when using domain.com/shiny instead of domain.com:3838).
analysed_ex.csv

Jan Stanstrup

unread,
Jun 13, 2014, 9:54:59 AM6/13/14
to shiny-...@googlegroups.com
Example input file was malformed. Attached is a correct file.
analysed_ex.csv

Yihui Xie

unread,
Jun 15, 2014, 6:08:00 PM6/15/14
to Jan Stanstrup, shiny-discuss
This error message seems to indicate that the WebSocket could not
decode the message. From my experience, this means the message
probably contained multi-byte characters that were not appropriately
encoded, which could be a consequence of a locale bug that we recently
discovered and fixed in Shiny Server. If possible, please test a more
recent version of the Shiny Server:
https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-1.2.0.355-amd64.deb
Thanks!

Regards,
Yihui

Jan Stanstrup

unread,
Jun 20, 2014, 3:30:02 AM6/20/14
to shiny-...@googlegroups.com, stan...@gmail.com
Thank you for the reply. That version gives me some of the same symptoms as when I tried to compile from github. It seems that all items generated with renderUI/uiOutput are not displayed.
The console says:
WebSocket connection to 'ws://APP_PATH1/__sockjs__/102/pu8n9_sc/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
sockjs-0.3.min.js:27

But I got similar messages before that didn't seem to cause problems.

Another app I have cannot find some files with the new version:
GET http://APP_PATH2/js/responsiveTable.js 404 (Not Found) predret.com/:22

I am wondering if something changed that is conflicting with my redirection of the shiny port to a dir. In my apache config I have:

<VirtualHost *:80>
DocumentRoot /var/www/html
  <Proxy *>
    Allow from localhost
  </Proxy>

ProxyPass        /shiny/ http://localhost:3838/
ProxyPassReverse /shiny/ http://localhost:3838/
RedirectMatch permanent ^/shiny$ /shiny/
</VirtualHost>


If I access the apps on the port directly it seems to work now. Any idea how to fix the redirection?


Jan.

Joe Cheng

unread,
Jun 20, 2014, 11:31:59 AM6/20/14
to Jan Stanstrup, shiny-...@googlegroups.com
If you're proxying through Apache then I think websocket failure is expected, and Shiny Server falls back to websocket emulation. Oh and looking at your original stack trace, indeed that's the case. Is the response code 400 the only error message that's showing up in the JavaScript console?




--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan Stanstrup

unread,
Jun 22, 2014, 6:58:39 AM6/22/14
to shiny-...@googlegroups.com, stan...@gmail.com
Yes it is the only message.

Jan Stanstrup

unread,
Jun 23, 2014, 4:19:08 AM6/23/14
to shiny-...@googlegroups.com, stan...@gmail.com
Some googling suggest that apache now includes a mod_proxy_wstunnel that should be able to redirect the websocket. But so far I fail to understand how to use it for shiny.
Any ideas? But I don't know if that is even the problem as my apps worked with previous versions.

Jan Stanstrup

unread,
Jul 1, 2014, 6:11:18 AM7/1/14
to shiny-...@googlegroups.com, stan...@gmail.com
Any ideas how to figure out what is going on here? The "Uncaught SyntaxError: Unexpected token N" was solved by the latest version. But I cannot get renderUI/uiOutput to display with the new version but it works with the old version.
It definitely seem to have to do with the proxying. But should there be a difference with the new version? If so any hints about how to resolve it would be greatly appreciated.

Fereshteh Karimeddini

unread,
Jul 9, 2014, 4:01:18 PM7/9/14
to shiny-...@googlegroups.com, stan...@gmail.com
Jan,

Sorry for delayed response. I verified that the new version of Shiny Server has a problem with certain proxy setups. We are looking into the issue, and possible workarounds for it.

Thanks for reporting the problem,
Fereshteh

Aurelien Tylski

unread,
Jul 15, 2014, 8:22:53 AM7/15/14
to shiny-...@googlegroups.com, stan...@gmail.com
I've the same problem, i hope you'll fix it fast. Thanks a lot for your job, shiny is just amazing ! ;)

Aurelien Tylski

unread,
Jul 17, 2014, 10:17:38 AM7/17/14
to shiny-...@googlegroups.com, stan...@gmail.com
Well well well, i don't know if it gonna help you but i give you a little information. Because i'm french i use accent (à é ê è and some letter like ç) and in some language those characters are not avaible... If i remove all those in my db (postgresql, i use Rpostgresql package) and in my ui... Well i don't have the "Uncaught SyntaxError: Unexpected token N" error... You might think it's stupid or useless, anyway i give you this information hoping it'll help :) . So can it be a problem like Shiny is not using UTF8 ? Or something like this ?

Well now i have to write a function to block to my user the possibility to use those characters... :) ! Thank a lot for your work on Shiny ;) have a nice day

Yihui Xie

unread,
Jul 21, 2014, 4:04:59 PM7/21/14
to Aurelien Tylski, shiny-discuss, Jan Stanstrup
The next version of shiny, 0.10.1, will require multi-byte characters
to be encoded in UTF-8. Please see the announcement for beta testing
here: https://groups.google.com/forum/#!topic/shiny-discuss/kT4GAm_FAYU

Regards,
Yihui
Reply all
Reply to author
Forward
0 new messages