Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Forked from gdepalma/server.R
Last active December 10, 2015 21:29
Show Gist options
  • Save jcheng5/4495659 to your computer and use it in GitHub Desktop.
Save jcheng5/4495659 to your computer and use it in GitHub Desktop.
library(shiny)
shinyServer(function(input, output) {
output$intense <- reactivePrint(function() {
if(input$panel==2){
Sys.sleep(10)
return('Finished')
}else({return(NULL)})
})
})
<script type="text/javascript">
var wasBusy = false;
var elapsedTimer = null;
var startTime = null;
function updateBusy() {
var isBusy = $('html').hasClass('shiny-busy');
if (isBusy && !wasBusy) {
startTime = new Date().getTime();
elapsedTimer = setInterval(function() {
var millisElapsed = new Date().getTime() - startTime;
$('#progress').text(Math.round(millisElapsed/1000) + ' seconds have elapsed');
}, 1000);
}
else if (!isBusy && wasBusy) {
clearInterval(elapsedTimer);
}
wasBusy = isBusy;
}
</script>
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Testing..."),
sidebarPanel(
helpText("Panel compute is where I wish for a 'progress bar' to show how much
time has elapsed.")
),
mainPanel(
tabsetPanel(
tabPanel("Start",value=1),
tabPanel("Compute", list(
### long function
verbatimTextOutput("intense")),
value=2),id='panel'),
### show timer
conditionalPanel("updateBusy() || $('html').hasClass('shiny-busy')",
id='progressIndicator',
"HI I'M IN PROGRESS",
div(id='progress',includeHTML("timer.js"))
),
tags$head(tags$style(type="text/css",
'#progressIndicator {',
' position: fixed; top: 8px; right: 8px; width: 200px; height: 50px;',
' padding: 8px; border: 1px solid #CCC; border-radius: 8px;',
'}'
))
)
))
@dmenne
Copy link

dmenne commented May 15, 2014

In the CSS, it should be #progress, not #progressIndicator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment