Open jelkink opened 4 years ago
I'm surprised that the error happens with runExample("01_hello", port = 80)
, where the host
isn't specified -- it shouldn't be listening at all on external-facing IP addresses without the host
.
I'm not able to reproduce the problem with the following, which is also on Ubuntu 20.04:
docker run --rm -p8080:80 -ti wch1/r-devel
RD
install.packages("shiny")
library(shiny)
runExample('01_hello', port = 80, host = "0.0.0.0")
And then I visit the host at port 8080.
Thanks for checking!
I'm trying to replicate your example, but have difficulties compiling httpuv as part of the installation of shiny. A memory problem, I think - I'll keep trying!
As for the host, I did actually have this line first:
options(shiny.host = "0.0.0.0")
but since the equivalent for the port was ignored (hence me putting in the port option in the runExample command), I assumed the host was also ignored. But it did then bind to 0.0.0.0 indeed.
When running exactly your example - using wch1/r-devel, RD, and installing shiny fresh, on my local Docker, I obtain the same error:
> library(shiny)
> runExample('01_hello', port = 80, host = "0.0.0.0")
Listening on http://0.0.0.0:80
/usr/bin/xdg-open: 869: www-browser: not found
/usr/bin/xdg-open: 869: links2: not found
/usr/bin/xdg-open: 869: elinks: not found
/usr/bin/xdg-open: 869: links: not found
/usr/bin/xdg-open: 869: lynx: not found
/usr/bin/xdg-open: 869: w3m: not found
xdg-open: no method available for opening 'http://127.0.0.1:80'
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
Warning: Error in rawToChar: embedded nul in string: 'YM\004V\027\037V\0OMBA\017\006\tL\027\v\rV\0020\031P\0170\004M\020\033\002C\016\nN\030A\003\003A\002\003\004M\020\033N\016AA\017N\n\n\002V\a\016\030C<\032\036N<K\r\030\rO\027\r6[\021\06]\006\r\033M\vNS\fA@K\0\0\0\0K\r\030\rO\027\r6[\021\06F\002\037\001q\n\002\0Z\n\r\005\fYNK\002AB\nB\n\t\aZ\a\r\035O<\031\033B<\004\b]\vNS\fA@K\0\0\0\0K\r\030\rO\027\r6]\n\002\016'
[No stack trace available]
Error in rawToChar(data) :
embedded nul in string: 'YM\004V\027\037V\0OMBA\017\006\tL\027\v\rV\0020\031P\0170\004M\020\033\002C\016\nN\030A\003\003A\002\003\004M\020\033N\016AA\017N\n\n\002V\a\016\030C<\032\036N<K\r\030\rO\027\r6[\021\06]\006\r\033M\vNS\fA@K\0\0\0\0K\r\030\rO\027\r6[\021\06F\002\037\001q\n\002\0Z\n\r\005\fYNK\002AB\nB\n\t\aZ\a\r\035O<\031\033B<\004\b]\vNS\fA@K\0\0\0\0K\r\030\rO\027\r6]\n\002\016'
The warning "Warning: Error in safeFromJSON" occurs after I access this Docker through a web server (Opera) on my local computer.
On reloading the website, the error usually occurs once I drag the slider; it sometimes occurs immediately; and it sometimes occurs after moving the slider a few times.
Trying the example on the remote droplet fails, due to memory issues when installing httpuv, but I guess that can be circumvented by pushing my local image to Docker hub. But the problem with the JSON conversion remains and it is not clear to me what the difference is between my test and yours.
I'm also unable to reproduce using rocker/shiny
, with these commands (and visiting port 8080 on the host with Chrome and Firefox):
docker run --rm -p8080:80 -ti rocker/shiny /bin/bash
R
install.packages('sessioninfo')
library(shiny)
sessioninfo::session_info()
runExample('01_hello', port = 80, host = "0.0.0.0")
> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.0.3 (2020-10-10)
os Ubuntu 20.04 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Etc/UTC
date 2020-10-21
─ Packages ───────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] RSPM (R 4.0.0)
cli 2.1.0 2020-10-12 [1] RSPM (R 4.0.2)
crayon 1.3.4 2017-09-16 [1] RSPM (R 4.0.0)
digest 0.6.25 2020-02-23 [1] RSPM (R 4.0.0)
fansi 0.4.1 2020-01-08 [1] RSPM (R 4.0.0)
fastmap 1.0.1 2019-10-08 [1] RSPM (R 4.0.0)
glue 1.4.2 2020-08-27 [1] RSPM (R 4.0.2)
htmltools 0.5.0 2020-06-16 [1] RSPM (R 4.0.1)
httpuv 1.5.4 2020-06-06 [1] RSPM (R 4.0.2)
jsonlite 1.7.1 2020-09-07 [1] RSPM (R 4.0.2)
later 1.1.0.1 2020-06-05 [1] RSPM (R 4.0.2)
magrittr 1.5 2014-11-22 [1] RSPM (R 4.0.0)
mime 0.9 2020-02-04 [1] RSPM (R 4.0.0)
promises 1.1.1 2020-06-09 [1] RSPM (R 4.0.2)
R6 2.4.1 2019-11-12 [1] RSPM (R 4.0.0)
Rcpp 1.0.5 2020-07-06 [1] RSPM (R 4.0.2)
rlang 0.4.8 2020-10-08 [1] RSPM (R 4.0.2)
sessioninfo 1.1.1 2018-11-05 [1] RSPM (R 4.0.0)
shiny * 1.5.0 2020-06-23 [1] RSPM (R 4.0.2)
withr 2.3.0 2020-09-22 [1] RSPM (R 4.0.2)
xtable 1.8-4 2019-04-21 [1] RSPM (R 4.0.0)
[1] /usr/local/lib/R/site-library
[2] /usr/local/lib/R/library
> runExample('01_hello', port = 80, host = "0.0.0.0")
Listening on http://0.0.0.0:80
sh: 1: xdg-open: not found
The data that you're seeing is received from a websocket connection that Shiny uses for communication (in contrast to the initial GET /
of the web page). It should be JSON -- it looks like it's getting corrupted somehow.
One more thought: if you run options(shiny.trace=TRUE)
before calling runExample()
, it will print out the traffic being sent and received by the server. That information may be helpful for figuring this out. For example:
> options(shiny.trace=T)
> runExample('01_hello', port = 80, host = "0.0.0.0")
Listening on http://0.0.0.0:80
sh: 1: xdg-open: not found
SEND {"config":{"workerId":"","sessionId":"2f70d9c1b79a7847284c92fdde51a31f","user":null}}
RECV {"method":"init","data":{"bins":30,".clientdata_output_distPlot_width":886,".clientdata_output_distPlot_height":400,".clientdata_output_distPlot_bg":"rgb(255, 255, 255)",".clientdata_output_distPlot_fg":"rgb(51, 51, 51)",".clientdata_output_distPlot_accent":"rgb(51, 122, 183)",".clientdata_output_distPlot_font":{"families":["Helvetica Neue","Helvetica","Arial","sans-serif"],"size":"14px"},".clientdata_output_distPlot_hidden":false,".clientdata_pixelratio":2,".clientdata_url_protocol":"http:",".clientdata_url_hostname":"10.0.0.5",".clientdata_url_port":"8080",".clientdata_url_pathname":"/",".clientdata_url_search":"",".clientdata_url_hash_initial":"",".clientdata_url_hash":"",".clientdata_singletons":"",".clientdata_allowDataUriScheme":true}}
SEND {"custom":{"showcase-src":{"srcref":[45,33,52,45,33,45],"srcfile":"app.R"}}}
SEND {"busy":"busy"}
SEND {"custom":{"showcase-src":{"srcref":[45,33,52,45,33,45],"srcfile":"app.R"}}}
SEND {"recalculating":{"name":"distPlot","status":"recalculating"}}
SEND {"recalculating":{"name":"distPlot","status":"recalculated"}}
SEND {"busy":"idle"}
SEND {"errors":{},"values":{"distPlot":{"src":"data:image/png;[base64 data]","width":886,"height":400,"coordmap":{"panels":[{"domain":{"left":40.88,"right":98.12,"bottom":-1.08,"top":28.08},"range":{"left":118.08,"right":1711.52,"bottom":652.12,"top":117.08},"log":{"x":null,"y":null},"mapping":{}}],"dims":{"width":1772,"height":800}}}},"inputMessages":[]}
RECV {"method":"update","data":{".clientdata_output_distPlot_width":575}}
SEND {"progress":{"type":"binding","message":{"id":"distPlot"}}}
SEND {"busy":"busy"}
SEND {"custom":{"showcase-src":{"srcref":[45,33,52,45,33,45],"srcfile":"app.R"}}}
SEND {"recalculating":{"name":"distPlot","status":"recalculating"}}
SEND {"recalculating":{"name":"distPlot","status":"recalculated"}}
SEND {"busy":"idle"}
SEND {"errors":{},"values":{"distPlot":{"src":"data:image/png;[base64 data]","width":575,"height":400,"coordmap":{"panels":[{"domain":{"left":40.88,"right":98.12,"bottom":-1.08,"top":28.08},"range":{"left":118.08,"right":1089.52,"bottom":652.12,"top":117.08},"log":{"x":null,"y":null},"mapping":{}}],"dims":{"width":1150,"height":800}},"error":null}},"inputMessages":[]}
Unfortunately, behaviour is not always consistent - sometimes it takes a little while before the error appears. It always appears though.
Note that the histogram never appears - just the slider.
The last test I observed this upon opening in the browser:
> runExample('01_hello', port = 80, host = "0.0.0.0")
Listening on http://0.0.0.0:80
/usr/bin/xdg-open: 869: www-browser: not found
/usr/bin/xdg-open: 869: links2: not found
/usr/bin/xdg-open: 869: elinks: not found
/usr/bin/xdg-open: 869: links: not found
/usr/bin/xdg-open: 869: lynx: not found
/usr/bin/xdg-open: 869: w3m: not found
xdg-open: no method available for opening 'http://127.0.0.1:80'
SEND {"config":{"workerId":"","sessionId":"541ed01f702af629d6ab03001c4547ad","user":null}}
RECV T /websocket/ HTTP/1.1
Host: localhost:8080
Connection: Upgrade
Prma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) ApplebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284
grade: websocket
Origin: http://localhost:8080
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br
cept-Language: en-GB,en-US;q=0.9,en;q=0.8
Sec-WebSocket-Key: GrV/66AzdDqHwGstKtNUsQ==
Sec-WebSock-Extensions: permessage-deflate; client_max_window_bits
???O??}m??r'??$uߛh&??*m??r.??}m??h<??5??(,??c!??g;??i+ ??nm??4x??(,??c!??g;??i:??s;??o<??j ????n;??2??$a??o*??b.??Y ??v:??b&??V#??Y-?Џ?dg??3c??3z??4z??$c??e#??h;??r.??s;??r??u;??i;??am??t(??3~??3~??3~??*mӑj&??r+??g??r???Y+??r??r??e*??$u?-??7c??4}??7w??$c??e#??h;??r.??s;??r??u;??i;??i!??<4ߔg"??o*??<ߺc#??r&??&??cm??N*??c;??gm??G=
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
and then when pressing reload, to try a second time, this:
SEND {"config":{"workerId":"","sessionId":"c0341ed3e49186821551538d087c8519","user":null}}
RECV T /websocket/ HTTP/1.1
Host: localhost:8080
Connection: Upgrade
Prma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) ApplebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284
grade: websocket
Origin: http://localhost:8080
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br
cept-Language: en-GB,en-US;q=0.9,en;q=0.8
Sec-WebSocket-Key: cRpJ9Hvk6fH2T7pYRcNttA==
Sec-WebSock-Extensions: permessage-deflate; client_max_window_bits
???4?+XO?F=@?D<? 1Z?_z?O9@? bO?I1Z? b?z?G1Q?_<U?J[?Y?V?m?
j?x?qvW?B=Z?O9@?t7A?[-@?O1G?{4[?t>S?zF?Ip?x?x?z?;X?N6@?J,U?D-@?^,k?B+@?G7@?J;W?E,? *S?m?
i??q? vW?B=Z?O9@?t7A?[-@?O1G?{4[?t>[?_z? >U?B4]?Xz?Q6]=@?H9?N-Q?z|?G.Q?B;U?zu?B9X?zG?E+?N*]? ?X1N? b?(L?Vt
3
9
6
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
It certainly looks very different from the JSON messages over the WebSocket that you are seeing!
What happens when you try a different browser?
This is with Chrome instead (86.0.4240.80):
SEND {"config":{"workerId":"","sessionId":"fde1bddc2bc8a8926e48f4ffac3526a5","user":null}}
SEND {"config":{"workerId":"","sessionId":"2ae3086b1de8a52eda86dad9ca79ad60","user":null}}
RECV ]??????????.??????S??əBD??PC??\Q??EX??R_????
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
Note that after this first SEND, I moved the slider a couple of times and nothing happens. No errors, but also no histogram. The second SEND is immediately after pressing reload.
This is upon opening in Firefox (81.0.2):
SEND {"config":{"workerId":"","sessionId":"4333d54872be7b2e202799c138815f35","user":null}}
RECV $$binary data$$
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
In the Opera case, it looks like it's trying to make a new websocket connection request, on an existing websocket connection. I don't know what's happening with Chrome and Firefox.
Do you have any security software that could be modifying the traffic sent from the browser?
Also, can you use the exact set of Docker commands I provided with rocker/shiny
? I want to make sure we're using as similar a setup as possible. It looks like your Docker image is different (since it's searching for other browsers when running the app).
I will do that, although with wch1/r-devel I used the exact same steps as you.
It had not occurred to me to use a different computer. Accessing the web server using my phone seems to work. I am unaware of any security software running on my laptop, but it appears something is interfering regardless of which browser I use.
In the meantime, my colleague has also been able to use the ggplotgui interface I have running on the web server. So it appears something specific about my local web browsers, indeed, which is rather surprising.
This is after re-pulling the rocker/shiny image from Docker hub (using my laptop Opera browser):
> library(shiny)
> options(shiny.trace=T)
> runExample("01_hello", port=80, host="0.0.0.0")
Listening on http://0.0.0.0:80
sh: 1: xdg-open: not found
SEND {"config":{"workerId":"","sessionId":"01ba3827744fe37cef6b4f7200f9938d","user":null}}
RECV T /websocket/ HTTP/1.1
Host: localhost:8080
Connection: Upgrade
Prma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) ApplebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284
grade: websocket
Origin: http://localhost:8080
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br
cept-Language: en-GB,en-US;q=0.9,en;q=0.8
Sec-WebSocket-Key: e0vPW2MQXY0CifY1Ig7I4A==
Sec-WebSock-Extensions: permessage-deflate; client_max_window_bits
???t?"?Op
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
7X?V {?G7N?
v?G{
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
G9B3 K
6O
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
RECV JVe?}q?VE?VJ?Kr?
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
RECV a?Wg?Qp?A}V?
Warning: Error in safeFromJSON: Argument 'txt' is not a valid JSON string.
[No stack trace available]
Error in safeFromJSON(charData, simplifyVector = FALSE) :
Argument 'txt' is not a valid JSON string.
With the following configuration:
> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.0.3 (2020-10-10)
os Ubuntu 20.04 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Etc/UTC
date 2020-10-21
─ Packages ───────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] RSPM (R 4.0.0)
cli 2.1.0 2020-10-12 [1] RSPM (R 4.0.2)
crayon 1.3.4 2017-09-16 [1] RSPM (R 4.0.0)
digest 0.6.25 2020-02-23 [1] RSPM (R 4.0.0)
fansi 0.4.1 2020-01-08 [1] RSPM (R 4.0.0)
fastmap 1.0.1 2019-10-08 [1] RSPM (R 4.0.0)
glue 1.4.2 2020-08-27 [1] RSPM (R 4.0.2)
htmltools 0.5.0 2020-06-16 [1] RSPM (R 4.0.1)
httpuv 1.5.4 2020-06-06 [1] RSPM (R 4.0.2)
jsonlite 1.7.1 2020-09-07 [1] RSPM (R 4.0.2)
later 1.1.0.1 2020-06-05 [1] RSPM (R 4.0.2)
magrittr 1.5 2014-11-22 [1] RSPM (R 4.0.0)
mime 0.9 2020-02-04 [1] RSPM (R 4.0.0)
promises 1.1.1 2020-06-09 [1] RSPM (R 4.0.2)
R6 2.4.1 2019-11-12 [1] RSPM (R 4.0.0)
Rcpp 1.0.5 2020-07-06 [1] RSPM (R 4.0.2)
rlang 0.4.8 2020-10-08 [1] RSPM (R 4.0.2)
sessioninfo 1.1.1 2018-11-05 [1] RSPM (R 4.0.0)
shiny * 1.5.0 2020-06-23 [1] RSPM (R 4.0.2)
withr 2.3.0 2020-09-22 [1] RSPM (R 4.0.2)
xtable 1.8-4 2019-04-21 [1] RSPM (R 4.0.0)
[1] /usr/local/lib/R/site-library
[2] /usr/local/lib/R/library
It appears using port 8081 instead of 8080 also works. So something on my local configuration is affecting communicating with port 8080.
I am using shiny for a web app using Docker. The server starts to listen on the http port properly, but once I access it through a browser, it crashes, with:
"Error in safeFromJSON(charData, simplifyVector = FALSE) : Argument 'txt' is not a valid JSON string."
System details
Browser Version: Opera 71.0.3770.271, but same problem with Chrome
Example application or steps to reproduce the problem
The problem occurs with this code: https://github.com/jelkink/ggplotgui
The problem also occurs with simply:
Describe the problem in detail
I am using shiny for a web app using Docker. The server starts to listen on the http port properly, but once I access it through a browser, it crashes, with:
"Error in safeFromJSON(charData, simplifyVector = FALSE) : Argument 'txt' is not a valid JSON string."
Full stack trace:
It might be related to issues #2118
Avoiding the webbrowser and using netcat instead does not replicate the error:
returns the page without errors - but I cannot test interacting with the interface, of course.
Testing this Shiny app just locally in RStudio works fine. Problems occur when moving to the web server. This might be due to newer R versions, since the Docker image is generated new. My local configuration is: