shinydisconnect
shinydisconnect copied to clipboard
package will not work when Chrome local cache is in place
A simple example:
- Run the basic
shinydisconnect
example locally on Chrome, you should see a tab opens. - Stop the server from R or Rstudio.
- Directly close the shiny tab on Chrome, do not hit refresh or F5.
- Ctrl + shift + t to resume the previous tab.
or:
- open https://daattali.com/shiny/shinydisconnect-demo/
- archive this app from shinyapps.io
- and 4. same as above
You will find the app is back, All UI is clickable. As expected, for those need the backend will not work, but still, users can play around which is not ideal. In the original Shiny, this is prevented by the shiny-disconnected-overlay
. Sine you disabled it #shiny-disconnected-overlay { display: none !important; }
, the protection is gone.
Here is what I did:
- bring the
#shiny-disconnected-overlay
back but one layer below 99997, so the#ss-connect-dialog
is till on top. - Add a 3s (you can change it to any time) function on the app start to check if the server is connected, check every second. If yes, this function stops and will get deleted; if timeout, display the "Cannot connect to the server" message.
- change the text from
ss-connect-dialog
to.shiny-discon::before
and.shiny-discon-noserver
. I toggle the class later in js. - All js code is placed in a file instead of in shiny UI.
- the way you write your demo makes the connection checking function run undesirably. Most people use the
disconnetMessage
on the UI side, just like your other examples which are fine, my checker will be deleted after first 3s. In your, demo, you insert this to DOM and immediately stops the sever. So the script is inserted at the same time as the server closes. So my function runs after the sever is ended. So, it will first display your error message but 3s later change to "Cannot connect to the server". To fix this, I fake the socket after shinyapps.js delete it:
$(document).on('shiny:disconnected', function(event){
setTimeout(function() {
Shiny.shinyapp.$socket = 'fake';
}, 1000);
});
I tried locally and deployed it to my account with no problem, fixed this issue. Please try it out #5 .