r - 隐藏容器时操作按钮不起作用。 Shiny R

标签 r shiny shiny-server

我一直在使用shiny,我认为这很好,但是当我使用操作按钮功能时遇到问题,问题是如果隐藏了我要放置响应信息的容器,则操作按钮不起作用.

例如。

index.html

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Example Tabs</title>
 <script src ="shared/jquery.js"></script>
 <script src ="shared/shiny.js"></script>
 <script src ="actionbutton.js"></script>
</head>
<body>
 <form class="span12 menu-med-upload">
  <div class="row-fluid">
   <button id="uploadFasta" type="button" class="btn action-button shiny-bound-input" >go!</button>
   <button id="show">Show</button>
   <button id="hide">Hide</button>
  </div>
 </form>
 <div id="table" class="shiny-html-output">asdasd</div>
 <script>
  $("#table").hide();
  $("#show").on("click",function(){
   $("#table").show();
  });
 </script>
</body>
</html>

服务器.R

library(shiny)

shinyServer(function(input, output) {
 output$table <- renderText({
  if(input$uploadFasta == 0)
   return(NULL)
  return("Clicked!")
 })
})

如果我注释行 $("#table").hide();它可以正常工作,但如果隐藏,容器将无法工作。

谢谢大家。

最佳答案

不久前我偶然发现了一个非常相似的问题,尽管它影响了 input 元素。请参阅my question欲了解更多信息,以及链接的Google group discussion .

基本上,问题在于,如果在加载 DOM 时隐藏了 reactive 元素,Shiny 就会丢失该元素(不确定这是否是您的情况发生的情况) 。

无论如何,您可能想尝试两种可能的解决方案。

  • 第一个是在显示 table div 时触发 shown 事件。该解决方案更加细粒度,因为它允许您随时控制是否对任何隐藏元素使用react。为此,只需更改您的 Javascript 即可执行以下操作:

    $("#table").show().trigger('shown');
    
  • 另一种可能性是指示 Shiny 在隐藏时不要忽略 table div。该解决方案将使任何受影响的元素始终使用react。要实现此目的,请更改您的 server.R 文件以包含以下行:

    outputOptions(output, 'table', suspendWhenHidden=FALSE)
    

关于r - 隐藏容器时操作按钮不起作用。 Shiny R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19840745/

相关文章:

r - 如何在 Shiny 的应用程序中为循环内的多图生成输出?

r - 作为条件面板条件的数字输出值

r - 我们如何配置shinyserver开源支持并发用户

r - 错误: package ‘digest’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version

r - 在 R 中转换字符串

R : know table(s), 如何计算四分位数)

R2PPT 使 R 崩溃; R2PPT 有替代品吗?

R 预测包 - 加法和乘法 hw() - 在 ETS 函数中等效

css - 在 R 中的 Shiny 应用程序中更改整个字体的最简单方法?

r - 如何在 Shiny 应用程序结束时终止所有进程?