문제

I have been working with shiny and I think that is so good, but I have a problem when use action button function, the problem is if hidden the container where I going to put information of response, the action button does not work.

For example.

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>

server.R

library(shiny)

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

if I comment the line $("#table").hide(); it works with out problem, but if hidden the container does not work.

Thanks for all.

도움이 되었습니까?

해결책

I stumbled on a very similar problem not long ago, although it affected an input element. See my question for more information, as well as the linked Google group discussion.

Basically, the problem was that Shiny loses track of a reactive element if it is hidden when loading the DOM (not sure if this is what happens in your case).

Anyway, you might want to try 2 possible solutions.

  • First one is to trigger the shown event when showing the table div. This solution is more fine-grained as it allows you to control at every moment whether to react or not to any hidden element. To do this just change your Javascript to do following:

    $("#table").show().trigger('shown');
    
  • The other possibility is to instruct Shiny not to ignore the table div when it is hidden. This solution will make any affected element react always. To achieve this change your server.R file to include this line:

    outputOptions(output, 'table', suspendWhenHidden=FALSE)
    
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top