我一直在尋找這一點。大多數人建議有條件的面板,像這樣:
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