disconnectMessage {shinydisconnect} | R Documentation |
Show a nice message when a shiny app disconnects or errors
Description
A shiny app can disconnect for a variety of reasons: an unrecoverable error occurred in
the app, the server went down, the user lost internet connection, or any other reason
that might cause the shiny app to lose connection to its server.
Call disonnectMessage()
anywhere in a Shiny app's UI to add a nice message when this happens. Works
locally (running Shiny apps within RStudio) and on Shiny servers (such as shinyapps.io,
RStudio Connect, Shiny Server Open Source, Shiny Server Pro).
See the demo Shiny app online for examples.
Note that it's not possible to distinguish between errors and timeouts - they will both
show the same message.
Usage
disconnectMessage(
text = "An error occurred. Please refresh the page and try again.",
refresh = "Refresh",
width = 450,
top = 50,
size = 22,
background = "white",
colour = "#444444",
overlayColour = "black",
overlayOpacity = 0.6,
refreshColour = "#337ab7",
css = ""
)
Arguments
text |
The text to show in the message. |
refresh |
The text to show in a link that allows the user to refresh the page.
Use |
width |
The width of the message box. Must be either an integer, or the string
|
top |
The distance from the message to the top of the page. Must be either
an integer, or the string |
size |
The font size of the text. (integer). |
background |
The background colour of the message box. |
colour |
The colour of the text of the message box. |
overlayColour |
The colour of the overlay to draw on the page behind the message box.
An overlay is used to "grey out" the application and draw attention to the message. Use
|
overlayOpacity |
The opacity of the overlay, from 0 (fully transparent/not visible) to 1
(fully opaque). Use |
refreshColour |
The colour of the refresh text link |
css |
Any additional CSS rules to apply to the message box. For example,
|
Details
You can also use disconnectMessage2()
to use a pre-set combination of parameters
that produces a large centered message.
Examples
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
disconnectMessage(),
actionButton("disconnect", "Disconnect the app")
),
server = function(input, output, session) {
observeEvent(input$disconnect, {
session$close()
})
}
)
}