mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Add "force" option to allowReconnect
This commit is contained in:
21
R/shiny.R
21
R/shiny.R
@@ -242,13 +242,16 @@ workerId <- local({
|
||||
#' (as opposed to the request that downloaded the web page for the app).
|
||||
#' }
|
||||
#' \item{allowReconnect(value)}{
|
||||
#' If \code{value} is \code{TRUE}, this tells the browser that, if the
|
||||
#' session ends due to the network connection closing, attempt to reconnect
|
||||
#' to the server. If a reconnection is successful, the browser will send all
|
||||
#' the current input values to the new session on the server, and the server
|
||||
#' will recalculate any outputs and send them back to the client. If
|
||||
#' \code{value} is \code{FALSE}, reconnections will be disabled (this is the
|
||||
#' default state).
|
||||
#' If \code{value} is \code{TRUE} and run in a hosting environment (Shiny
|
||||
#' Server or Connect) with reconnections enabled, then when the session ends
|
||||
#' due to the network connection closing, the client will attempt to
|
||||
#' reconnect to the server. If a reconnection is successful, the browser will
|
||||
#' send all the current input values to the new session on the server, and
|
||||
#' the server will recalculate any outputs and send them back to the client.
|
||||
#' If \code{value} is \code{FALSE}, reconnections will be disabled (this is
|
||||
#' the default state). If \code{"force"}, then the client browser will always
|
||||
#' attempt to reconnect. The only reason to use \code{"force"} is for testing
|
||||
#' on a local connection (without Shiny Server or Connect).
|
||||
#' }
|
||||
#' \item{sendCustomMessage(type, message)}{
|
||||
#' Sends a custom message to the web page. \code{type} must be a
|
||||
@@ -541,8 +544,8 @@ ShinySession <- R6Class(
|
||||
},
|
||||
|
||||
allowReconnect = function(value) {
|
||||
if (!(identical(value, TRUE) || identical(value, FALSE))) {
|
||||
stop("value must be TRUE or FALSE")
|
||||
if (!(identical(value, TRUE) || identical(value, FALSE) || identical(value, "force"))) {
|
||||
stop('value must be TRUE, FALSE, or "force"')
|
||||
}
|
||||
private$write(toJSON(list(allowReconnect = value)))
|
||||
},
|
||||
|
||||
@@ -86,13 +86,16 @@
|
||||
(as opposed to the request that downloaded the web page for the app).
|
||||
}
|
||||
\item{allowReconnect(value)}{
|
||||
If \code{value} is \code{TRUE}, this tells the browser that, if the
|
||||
session ends due to the network connection closing, attempt to reconnect
|
||||
to the server. If a reconnection is successful, the browser will send all
|
||||
the current input values to the new session on the server, and the server
|
||||
will recalculate any outputs and send them back to the client. If
|
||||
\code{value} is \code{FALSE}, reconnections will be disabled (this is the
|
||||
default state).
|
||||
If \code{value} is \code{TRUE} and run in a hosting environment (Shiny
|
||||
Server or Connect) with reconnections enabled, then when the session ends
|
||||
due to the network connection closing, the client will attempt to
|
||||
reconnect to the server. If a reconnection is successful, the browser will
|
||||
send all the current input values to the new session on the server, and
|
||||
the server will recalculate any outputs and send them back to the client.
|
||||
If \code{value} is \code{FALSE}, reconnections will be disabled (this is
|
||||
the default state). If \code{"force"}, then the client browser will always
|
||||
attempt to reconnect. The only reason to use \code{"force"} is for testing
|
||||
on a local connection (without Shiny Server or Connect).
|
||||
}
|
||||
\item{sendCustomMessage(type, message)}{
|
||||
Sends a custom message to the web page. \code{type} must be a
|
||||
|
||||
@@ -82,12 +82,6 @@ var ShinyApp = function() {
|
||||
var ws = new WebSocket(protocol + '//' + window.location.host + defaultPath);
|
||||
ws.binaryType = 'arraybuffer';
|
||||
|
||||
// This flag indicates that reconnections are permitted by the server.
|
||||
// When Shiny is running with Shiny Server, this flag will be present
|
||||
// only on versions of SS that support reconnects. When running Shiny
|
||||
// locally, this is set to true, because the "server" always permits
|
||||
// reconnection.
|
||||
ws.allowReconnect = true;
|
||||
return ws;
|
||||
};
|
||||
|
||||
@@ -225,8 +219,12 @@ var ShinyApp = function() {
|
||||
}
|
||||
|
||||
// To try a reconnect, both the app (this.$allowReconnect) and the
|
||||
// server (this.$socket.allowReconnect) must allow reconnections.
|
||||
if (this.$allowReconnect === true && this.$socket.allowReconnect === true) {
|
||||
// server (this.$socket.allowReconnect) must allow reconnections, or
|
||||
// session$allowReconnect("force") was called. The "force" option should
|
||||
// only be used for testing.
|
||||
if ((this.$allowReconnect === true && this.$socket.allowReconnect === true) ||
|
||||
this.$allowReconnect === "force")
|
||||
{
|
||||
var delay = reconnectDelay.next();
|
||||
exports.showReconnectDialog(delay);
|
||||
this.$scheduleReconnect(delay);
|
||||
@@ -591,10 +589,11 @@ var ShinyApp = function() {
|
||||
});
|
||||
|
||||
addMessageHandler('allowReconnect', function(message) {
|
||||
if (!(message === true || message === false)) {
|
||||
if (message === true || message === false || message === "force") {
|
||||
this.$allowReconnect = message;
|
||||
} else {
|
||||
throw "Invalid value for allowReconnect: " + message;
|
||||
}
|
||||
this.$allowReconnect = message;
|
||||
});
|
||||
|
||||
addMessageHandler('custom', function(message) {
|
||||
|
||||
Reference in New Issue
Block a user