Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Last active May 20, 2017 00:27
Show Gist options
  • Save jcheng5/90665be81d8c2ae49fc842953d51a8ff to your computer and use it in GitHub Desktop.
Save jcheng5/90665be81d8c2ae49fc842953d51a8ff to your computer and use it in GitHub Desktop.
Artificially slow Shiny app for testing/debugging purposes
library(shiny)
# Configure delays using the following constants.
# before worker starts responding to listeners
STARTUP_DELAY_SECS = 0
# time to load ui.R (before first "/" response only)
UI_INIT_DELAY_SECS = 0
# before any "/" response (including first)
UI_DELAY_SECS = 0
# time spent on the client after "/" response but before requesting websocket
CLIENT_DELAY_SECS = 2
# time to load server.R (before first websocket conn only)
SERVER_INIT_DELAY_SECS = 0
# time for websocket conn to be processed (every time, including first)
SERVER_DELAY_SECS = 0
# End config constants
start_time <- Sys.time()
options(digits.secs = 3)
Sys.sleep(STARTUP_DELAY_SECS)
Sys.sleep(SERVER_INIT_DELAY_SECS)
function(input, output, session) {
Sys.sleep(SERVER_DELAY_SECS)
output$time <- renderText(format(Sys.time()))
output$pid <- renderText(Sys.getpid())
}
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;
# reconnect false;
# Define a server that listens on port 3838
server {
listen 3838;
# Define a location at the base URL
location / {
# Host the directory of Shiny Apps stored in this directory
site_dir /shiny-server/superslow;
# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;
# When a user visits the base URL rather than a particular application,
# an index of the applications available in this directory will be shown.
directory_index on;
utilization_scheduler 1 0.2 20;
}
}
admin 4151 {
required_user "**";
}
Sys.sleep(UI_INIT_DELAY_SECS)
function(req) {
Sys.sleep(UI_DELAY_SECS)
fluidPage(
tags$script(HTML(sprintf("
function sleep(seconds)
{
var e = new Date().getTime() + (seconds * 1000);
while (new Date().getTime() <= e) {}
}
sleep(%f);
", CLIENT_DELAY_SECS))),
withTags(
table(
tr(
td("Process started at:"),
td(format(start_time))
),
tr(
td("UI generated at:"),
td(format(Sys.time() - start_time))
),
tr(
td("Server executed at:"),
td(textOutput("time", inline = TRUE))
),
tr(
td("UI process PID:"),
td(Sys.getpid())
),
tr(
td("Server process PID:"),
td(textOutput("pid", inline = TRUE))
)
)
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment