14

注 : このオブジェクトに関するほとんどすべての議論を、光沢のある googlegroups とここ SO で読みました。

光沢のあるサーバーがビジーであることを示すインジケーターが必要です。光沢のあるインキュベーターを試してみましたが、問題は進行状況バーの最大値を設定できないことです。 私はこのようなものはしたくない: https://shiny.rstudio.com/gallery/progress-bar-example.htmlサーバーが計算している限り、どのタブを表示しても表示されます。(関連するタブだけでなく、タブセットの上にもあります)

4

5 に答える 5

15

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)
})
于 2014-10-02T11:46:41.377 に答える
2

show() ではなく、fadeIn() を使用すると、この点滅の発生を軽減できることがわかりました。

setInterval(function(){
                     if ($('html').attr('class')=='shiny-busy') {
                          setTimeoutConst = setTimeout(function(){
                                $('#loading-page').fadeIn(500);
                             }, delay);
                      } else {
                          clearTimeout(setTimeoutConst );
                          $('#loading-page').hide();
                      }
              },10)
于 2017-03-07T19:13:32.597 に答える