I am using shiny to build a web application. Some steps will take some time to calculate, so I want to add a calculation in process indicator in shiny application.
I found Show that Shiny is busy (or loading) when changing tab panels in stackoverflow, but the shinyIncubator
package seams need to specify min and max.
Then I found this blog:http://withr.me/blog/2014/01/03/add-calculation-in-process-indictor-for-shiny-application/ He provided a great way to do this.
shinyUI(bootstrapPage(
# Add custom CSS & Javascript;
tagList(
tags$head(
tags$link(rel="stylesheet", type="text/css",href="style.css"),
tags$script(type="text/javascript", src = "busy.js")
)
),
div(class = "busy",
p("Calculation in progress.."),
img(src="http://imageshack.us/a/img827/4092/ajaxloaderq.gif")
),
div(class = "span4", uiOutput("obs")),
div(class = "span8", plotOutput("distPlot"))
))
Java script;
setInterval(function(){
if ($('html').attr('class')=='shiny-busy') {
setTimeout(function() {
if ($('html').attr('class')=='shiny-busy') {
$('div.busy').show()
}
}, 1000)
} else {
$('div.busy').hide()
}
}, 100)
style.css
div.busy {
position:absolute;
top: 40%;
left: 50%;
margin-top: -100px;
margin-left: -50px;
display:none;
background: rgba(230, 230, 230, .8);
text-align: center;
padding-top: 20px;
padding-left: 30px;
padding-bottom: 40px;
padding-right: 30px;
border-radius: 5px;
}
So my question is how to add custom CSS and Javascript in my ui file? I tried to creat two separate files of js and css, but the indicator appears at the left-top constantly. Then I tried to put these two pieces of code directly in R, while definitely, syntax error. Thanks!
Problem solved: Create a folder called "www" and put thoes two files in it.