2014-09-23 94 views
8

注意:我已閱讀幾乎所有關於此對象的討論,閃亮的googlegroups和這裏在SO。閃亮的應用程序繁忙指示燈

我需要一個指示燈,顯示閃亮的服務器正忙。我嘗試過閃亮的孵化器,但問題是我無法爲進度條設置最大值。 我不想這樣的事情:http://shiny.rstudio.com/gallery/progress-example.html 我需要的是: 1-顯示一個繁忙的指示器消息和欄(即只是一個簡單的動畫欄,不需要顯示一個填充欄),只要服務器正在計算 2-無論您在查看哪個標籤,都會顯示它。 (不僅在相關的標籤,但在標籤集的頂部)

感謝

+0

該鏈接已死亡... – 2016-04-04 22:33:38

回答

8

我一直在尋找這一點。大多數人建議有條件的面板,像這樣:

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) 
}) 
+0

謝謝。我會嘗試一下,讓你知道結果 – 2014-10-02 18:49:38

0

繁忙格也出現爲閃亮的最新版本分裂秒,即使沒有明顯的計算是怎麼回事(這是不是在舊版本的問題)。閃亮似乎在短時間內處於忙碌狀態。作爲解決方案(補充上述討論),可以包括對條件處理的另一個第二次延遲驗證閃爍繁忙的html類。 JavaScript的部分看起來類似的東西(例如還包括檢查取決於反應textit兩種不同div.busy狀態):

 if(($('html').attr('class')=='shiny-busy')){ 
       setTimeout(function() { 
       if ($('html').attr('class')=='shiny-busy') { 
        if($('#textit').html()!='Waiting...'){ 
         $('div.busy1').show() 
        } 
        if($('#textit').html()=='Waiting...'){ 
         $('div.busy2').show() 
        } 
       } 
       },1000) 
       } else { 
       $('div.busy1').hide() 
       $('div.busy2').hide() 
       } 
      },100) 
1

我發現使用淡入(),而不是顯示()有助於緩解此閃爍發生:

setInterval(function(){ 
        if ($('html').attr('class')=='shiny-busy') { 
          setTimeoutConst = setTimeout(function(){ 
           $('#loading-page').fadeIn(500); 
          }, delay); 
         } else { 
          clearTimeout(setTimeoutConst); 
          $('#loading-page').hide(); 
         } 
       },10)