2018 年の更新: 現在、ローダーの表示に役立つ優れたパッケージがあります: shinycssloaders
(ソース: https://github.com/andrewsali/shinycssloaders )
私もこれを探していました。ほとんどの人は、次のような条件付きパネルを提案しています。
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 は、その div の表示と非表示を処理します。
setInterval(function(){
if ($('html').attr('class')=='shiny-busy') {
$('div.busy').show()
} else {
$('div.busy').hide()
}
},100)
追加の css を使用すると、アニメーション化されたビジーな画像が常に表示される位置に固定されるようにすることができます。
上記のいずれの場合でも、「シャイニービジー」状態はやや不正確で信頼できないことがわかりました: div は一瞬表示され、計算がまだ進行している間に消えます... その問題を修正するための汚い解決策を見つけました。少なくとも私のアプリでは。気軽に試してみてください。おそらく誰かが、これが問題を解決する方法と理由について洞察を与えることができます.
server.R では、2 つの reactValues を追加する必要があります。
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)
})