Coder Social home page Coder Social logo

daattali / shinydisconnect Goto Github PK

View Code? Open in Web Editor NEW
65.0 3.0 3.0 409 KB

🔌 Show a nice message when a Shiny app disconnects or errors

Home Page: https://daattali.com/shiny/shinydisconnect-demo

License: Other

R 93.39% CSS 6.61%
shiny r r-package rstats shiny-r

shinydisconnect's People

Contributors

daattali avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

shinydisconnect's Issues

Include Href in Text

Hi There,

First I have to say that this is great work! I really enjoyed this package.
I am making a web app in shiny and I just wonder is it possible to do something like : disconnectMessage(text = HTML(" Raw HTML")).
Right now it will not look at the strong tag and produce some other symbols in the popup window.

I think that this will be very useful for people using this package because they can include a link such as a feedback form once their users encounter a disconnect.

Different messages for error and session timeout?

This is not an issue as such, however, I was thinking it would be nice to have separate disconnect functions, one for errors and another one for session timeouts. Right now, if I customize the disconnect message for timeout, it doesn't look meaningful for the users when the app stops because of an error that had occurred and vice versa.

Error on loading

There seems to be an error that prevents application from loading if I insert in UI section.

    ui <- dashboardPage(
    disconnectMessage2(),
   further elements(...),

Then upon loading this happens:

<script>$(function() {  $(document).on('shiny:disconnected', function(event) {    $('#ss-connect-dialog').show();    $('#ss-overlay').show();  })});</script>
<div id="ss-connect-dialog" style="display: none;">
 <a id="ss-reload-link" href="#" onclick="window.location.reload(true);"></a>
</div>
<div id="ss-overlay" style="display: none;"></div>
Error in tagAssert(header, type = "header", class = "main-header") : 
 Expected an object with class 'shiny.tag'.

And nothing loads. What could this mean? Thanks.

package will not work when Chrome local cache is in place

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 .

enhancement - link to website

Hi there,
thanks for this great package!
I tried to use your code in app on shiny server open source to route users back to a log in website.
Therefore I adjusted your utils.R, simply trying to add a link.
Strangely, it still only reloads, even if I remove "onclick="window.location.reload(true);" replace with onclick="window.location='https://www....';" or just add a link to href.
Is this somehow hardcoded on the side of shiny server ?

shinydisconnect closes window without showing message

Hi Dean,

I'm trying to run shinydisconnect in 3 Windows computers and, in each one of them, when I click on the "Disconnect the app" action button, each obediently closes the page but no message, box, or little window shows up. The page is just closed and I'm left with the "Listening on http://127.0.0.1:..." standard message. This happens with both disconnectMessage and disconnectMessage2.

The reprex is virtually the same as in the demo (I just added the library(shinydisconnect) statement).

  library(shiny)
  library(shinydisconnect)

  shinyApp(
    ui = fluidPage(
      disconnectMessage(),
      actionButton("disconnect", "Disconnect the app")
    ),
    server = function(input, output, session) {
      observeEvent(input$disconnect, {
        session$close()
      })
    }
  )

However, everything works well in the demo page: https://daattali.com/shiny/shinydisconnect-demo/

Would you have any suggestion to make it work or, at least, to try to find out what's wrong on my side?

Thanks,

CW

I'm using Chrome Version 98.0.4758.102 (Official Build) (64-bit) in my 3 Windows computers. The RStudio/Shiny/Windows versions are:

  • 4.0.4/1.6.0/Windows 10
  • 4.0.3/1.5.0/Windows 10
  • 4.1.1/1.7.1/Windows 11

Feature request: Show error details

Thank you for this package, very useful. Not sure if it's possible, I've been looking all over for this: is it possible to display a message that shows the cause for disconnecting from the Shiny server? Preferably with a stack trace to the error. This will make it easier for users of an app to file a bug report, and for the developer to fix the problem.

The problem is probably that once the app is disconnected, you can’t get any information from the server, apart from what is been send to ‘event.socket’ by ‘shiny:disconnected’ to the client side (javascript). From what I could tell, this socket appears empty after a crash. Maybe you have some fresh ideas?

Thanks in advance!

Include additional functions to be triggered on error?

Hi, when a disconnect occurs (due to fatal error or timeout) I would like to also write at least the time, URL etc to a log. Is there any way to include an additional function, say within disconnectmessage(), eg myFunctionToWriteTheErrorToAFile() ? So that the user would still see the disconnect message but at least some basic information would be written to a file?

Reconnecting attempts vs Reload

The shinydisconnect package is great!
I'm curious about how one might also restyle the "attempting to reconnect" dance that Shiny performs (to salvage the SockJS robust socket) prior to a full disconnection requiring a page reload.

I suppose one could always write a bubbling event listener to swap-out the text in tags with this class ... but perhaps that could be included in the shinydisconnect package, too?

Add query string to reload URL

A nice addition to the reload process (though this requires a bit more FE code than the current onclick handler) would be to allow adding (or overwriting) an existing URL query parameter on the reload.

The main reason for this would be to allow for easier differentiation in logs between pageloads/reloads via initial requests or the browser's buttons and via the shinydisconnect interface itself.
Hypothetical example:

disconnectMessage(
  text = "Oops",
  refresh = "Click here to reload",
  query = list(
    "disconnectMessageReload" = 1
  )
)

query would either introduce new URL query string args or update existing ones (i.e. upsert) with the standard URL-encoded key/value pairs.

The server function (or fronting server -- e.g. NGINX -- logs) can then inspect the URL for that key to help track that behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.