2014-09-23 68 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)