我一直在使用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/