shinydisconnect icon indicating copy to clipboard operation
shinydisconnect copied to clipboard

package will not work when Chrome local cache is in place

Open lz100 opened this issue 3 years ago • 11 comments

A simple example:

  1. Run the basic shinydisconnect example locally on Chrome, you should see a tab opens.
  2. Stop the server from R or Rstudio.
  3. Directly close the shiny tab on Chrome, do not hit refresh or F5.
  4. Ctrl + shift + t to resume the previous tab.

or:

  1. open https://daattali.com/shiny/shinydisconnect-demo/
  2. archive this app from shinyapps.io
  3. 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:

  1. bring the #shiny-disconnected-overlay back but one layer below 99997, so the #ss-connect-dialog is till on top.
  2. 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.
  3. change the text from ss-connect-dialog to .shiny-discon::before and .shiny-discon-noserver. I toggle the class later in js.
  4. All js code is placed in a file instead of in shiny UI.
  5. 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 .

lz100 avatar Nov 27 '20 02:11 lz100