R/disconnectMessage.R
disconnectMessage.RdA 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.
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 = ""
)The text to show in the message.
The text to show in a link that allows the user to refresh the page.
Use refresh = "" if you don't want to show a refresh link.
The width of the message box. Must be either an integer, or the string
"full" to make the message take up the entire page width.
The distance from the message to the top of the page. Must be either
an integer, or the string "center" to make the box vertically centered.
The font size of the text. (integer).
The background colour of the message box.
The colour of the text of the message box.
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 = 0 to disable the overlay.
The opacity of the overlay, from 0 (fully transparent/not visible) to 1
(fully opaque). Use overlayOpacity = 0 to disable the overlay.
The colour of the refresh text link
Any additional CSS rules to apply to the message box. For example,
css = "padding: 0 !important; border: 3px solid red;" will remove padding and add a border.
Note that you may need to use the !important rule to override default styles.
You can also use disconnectMessage2() to use a pre-set combination of parameters
that produces a large centered message.
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
disconnectMessage(),
actionButton("disconnect", "Disconnect the app")
),
server = function(input, output, session) {
observeEvent(input$disconnect, {
session$close()
})
}
)
}