1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
shiny_url <- function(port) {
sprintf("http://127.0.0.1:%d/", port)
}
server_exists <- function(url) {
!inherits(
try({ suppressWarnings(readLines(url, 1)) }, silent = TRUE),
"try-error"
)
}
webshot_app_timeout <- function() {
getOption("webshot.app.timeout", 60)
}
wait_until_server_exists <- function(
url,
timeout = webshot_app_timeout()
) {
cur_time <- function() {
as.numeric(Sys.time())
}
start <- cur_time()
while(!server_exists(url)) {
if (cur_time() - start > timeout) {
stop(
'It took more than ', timeout, ' seconds to launch the Shiny Application. ',
'There may be something wrong. The process has been killed. ',
'If the app needs more time to be launched, set ',
'options(webshot.app.timeout) to a larger value.',
call. = FALSE
)
}
Sys.sleep(0.25)
}
TRUE
}
|