Websockets can be faster than plain HTTP(s) requests and browsers can usually open more websocket connections.
My browser is telling me via the javascript console that while my shiny app works and apache proxypass is proxying correctly, websockets aren't working:
WebSocket connection to 'wss://www.example.com/shiny/01_hello/__sockjs__/058/v193lng7/websocket' failed: WebSocket is closed before the connection is established.
I've seen different ways that Apache can be configured to proxy websockets. Such as:
ProxyPass /shiny/ ws://127.0.0.1:3838/ ProxyPass /shiny/ wss://127.0.0.1:3838/ RedirectMatch ^/shiny$ /shiny/
and:
RewriteEngine On RewriteCond %{REQUEST_URI} ^/socket.io [NC] RewriteCond %{QUERY_STRING} transport=websocket [NC] RewriteRule /(.*) ws://localhost:3001/$1 [P,L] ProxyPass / http://localhost:3001/ ProxyPassReverse / http://localhost:3001/
My question is, can any of these be adapted for use with shiny?
Shiny on hosted RStudio Server. Use Apache Spark inside Shiny apps.
Set up AWS Firewall to only allow connections to our https port. This will block direct http access to the Shiny Server. Install an SSL Certificate: Here, we'll install a free, self-generated certificate. But if you want, you can install a bought SSL certificate that makes sure the user will not get any warnings.
Most likely your R file is handeling Websockets badly.
In your HTML file in your java script, you have something like:
var socket = new WebSocket("wss://"+hostlocation, "HelloR")
And then the following functions which you define as you need:
socket.onopen = function() {} socket.onmessage = function got_packet(msg) {} socket.onclose = function(){}
And in your R code you have something something like:
w = create_server(webpage=static_text_service(htmldata)) f = function(DATA,WS,...) { list(msg,p)= process(data) websocket_broadcast(toJSON(list(msg=msg, fig=p)),WS$server) } set_callback("receive",f,w) ctmp = tempfile() itmp = tempfile() daemonize(w)
Where htmldata is your html file.
Then modify the httpd.conf to have:
<VirtualHost *:origin_port> ProxyPass /shiny/ ws://127.0.0.1:3838/ ProxyPassReverse /shiny/ ws://127.0.0.1:3838/ </VirtualHost>
where origin_port is the port number of origin and ws://127.0.0.1:3838/ is the address and port of the host.
Make sure you are not missing any of these critical parts. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With