Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 闪亮加载微调器显示过于频繁_Javascript_Jquery_R_Shiny - Fatal编程技术网

Javascript 闪亮加载微调器显示过于频繁

Javascript 闪亮加载微调器显示过于频繁,javascript,jquery,r,shiny,Javascript,Jquery,R,Shiny,我在Shinny中有一个加载微调器,其实现方式与t类似: conditionalPanel(condition=“$('html').hasClass('shinny-busy')”, 标记$div(“加载…”,id=“加载消息”) ) runApp(列表( ui=页面带边框( headerPanel(“测试”), 侧栏面板( 标签$head(标签$style(type=“text/css”,” #加载消息{ 位置:固定; 顶部:0px; 左:0px; 宽度:100%; 填充:5px0px 5p

我在Shinny中有一个加载微调器,其实现方式与t类似:

conditionalPanel(condition=“$('html').hasClass('shinny-busy')”,
标记$div(“加载…”,id=“加载消息”)
)
runApp(列表(
ui=页面带边框(
headerPanel(“测试”),
侧栏面板(
标签$head(标签$style(type=“text/css”,”
#加载消息{
位置:固定;
顶部:0px;
左:0px;
宽度:100%;
填充:5px0px 5px0px;
文本对齐:居中;
字体大小:粗体;
字体大小:100%;
颜色:#000000;
背景色:#CCFF66;
z指数:105;
}
")),
数字输入('n','OB数',100),
conditionalPanel(condition=“$('html').hasClass('shinny-busy')”,
标记$div(“加载…”,id=“加载消息”))
),
主面板(绘图输出(“绘图”))
),
服务器=功能(输入、输出){

输出$plot我有点搞不清楚我在看什么,但一般来说,看起来您依赖于
$('html').hasClass('shiny-busy')
来确定何时显示它,所以无论应用什么“shiny-busy”类,只要将其延迟一秒钟或其他任何时间。

如果我理解正确,任务就是显示特定的类和“busy”“忙碌”延迟一定时间后的消息。微调器必须仅在重要忙碌时间显示(可能超过一秒)

这可以通过
debounce
概念轻松实现

我将不提供代码片段,这取决于如何集成到您的代码中,但将提供伪代码,以便您了解如何使用它:

// flag of busyness
var isBusy = false;

// ...
// operation in progress, start the counting
isBusy = true;
_.debounce(showSpinner, 1000, {
   'trailing': true             // we need to trigger only when 1 seconds interval passed from last iteration
}));

// ... when done
hideSpinner();

// will be debounced after 1 second interval, and if still busy - the spinner will be shown
var showSpinner = function() {
    if (isBusy) {
        $('selector').addClass('shiny-busy');
    }
}

var hideSpinner = function() {
   isBusy = false;        // our external variable is used
   if ($('selector').hasClass('shiny-busy')) {
       $('selector').removeClass('shiny-busy');
   }
}

伪代码只是为了说明这个概念,但希望它能解释如何使用它。

我遇到了这个软件包:
shinysky
()

它有一个
busyIndicator
元素,您可以设置它在出现之前应该等待多长时间,您只需将
busyIndicator(wait=1000)
添加到您的
ui.R


您还可以通过在R中运行
busyIndicator
来查看函数的代码,它基本上是一些使用
setTimeout

的js代码,这就是正在发生的事情。我想知道如何使它只在显著的繁忙时间(可能超过一秒)显示微调器,但这正是我要说的。“重要”只是指在显示之前稍等片刻,因此如果它在阈值之前完成加载,微调器将不会显示,但如果加载超过阈值,则微调器将显示。如果您仍然需要帮助,请粘贴应用“重要”的代码“我想,
shinny busy
类来自shinny,所以我实际上没有代码(或者至少我不想尝试更改
shinny busy
类。我想我的意思是你正在做一些事情让它“忙”对吗?但是如果你不明确地做一些事情来调用“忙”信号,Shiny怎么知道它是“忙的”?Macainian,找到我上面的答案。谢谢你的讨论,它帮助理解了需要什么。的确。干得好@Farside.Solid find。ShinySky是一个很棒的软件包。
// flag of busyness
var isBusy = false;

// ...
// operation in progress, start the counting
isBusy = true;
_.debounce(showSpinner, 1000, {
   'trailing': true             // we need to trigger only when 1 seconds interval passed from last iteration
}));

// ... when done
hideSpinner();

// will be debounced after 1 second interval, and if still busy - the spinner will be shown
var showSpinner = function() {
    if (isBusy) {
        $('selector').addClass('shiny-busy');
    }
}

var hideSpinner = function() {
   isBusy = false;        // our external variable is used
   if ($('selector').hasClass('shiny-busy')) {
       $('selector').removeClass('shiny-busy');
   }
}