我一直在寻找这一点。大多数人建议有条件的面板,像这样:
conditionalPanel(
condition="!($('html').hasClass('shiny-busy'))",
img(src="images/busy.gif")
)
你总是可以给自己更多的控制和创造条件处理(也许取决于更多的东西),这样在你ui.R:
div(class = "busy",
p("Calculation in progress.."),
img(src="images/busy.gif")
)
其中一些JavaScript处理显示和隐藏该分区:
setInterval(function(){
if ($('html').attr('class')=='shiny-busy') {
$('div.busy').show()
} else {
$('div.busy').hide()
}
},100)
一些额外的CSS,你可以确保你的动画形象忙得到一个固定的地方现在的位置它将始终可见。
在上述任何一种情况下,我发现“发光 - 忙碌”条件有些不准确和不可靠:div显示一秒钟,并在计算仍在继续时消失... 我发现了一个肮脏的解决方案至少在我的应用程序中解决这个问题。随时尝试一下,也许有人可以提供解决问题的方法和原因。
在你server.R你需要添加两个reactiveValues:
shinyServer(function(input, output, session) {
# Reactive Value to reset UI, see render functions for more documentation
uiState <- reactiveValues()
uiState$readyFlag <- 0
uiState$readyCheck <- 0
然后,在你的renderPlot功能(或其他输出函数,其中计算上走),你使用这些活性值重置功能:
output$plot<- renderPlot({
if (is.null(input$file)){
return()
}
if(input$get == 0){
return()
}
uiState$readyFlag
# DIRTY HACK:
# Everytime "Get Plot" is clicked we get into this function
# In order for the ui to be able show the 'busy' indicator we
# somehow need to abort this function and then of course seamlessly
# call it again.
# We do this by using a reactive value keeping track of the ui State:
# renderPlot is depending on 'readyFlag': if that gets changed somehow
# the reactive programming model will call renderPlot
# If readyFlag equals readyCheck we exit the function (= ui reset) but in the
# meantime we change the readyFlag, so the renderHeatMap function will
# immediatly be called again. At the end of the function we make sure
# readyCheck gets the same value so we are back to the original state
isolate({
if (uiState$readyFlag == uiState$readyCheck) {
uiState$readyFlag <- uiState$readyFlag+1
return(NULL)
}
})
isolate({plot <- ...})
# Here we make sure readyCheck equals readyFlag once again
uiState$readyCheck <- uiState$readyFlag
return(plot)
})
该链接已死亡... – 2016-04-04 22:33:38