2014-07-02 63 views
1

我期待這個代碼寫出如果我按下按鈕的次數是偶數還是奇數?相反沒有任何反應閃亮的動態按鈕按下錯誤

的index.html

<html> 
    <head> 
     <script type="text/javascript" src="shared/jquery.js"></script> 
     <script type="text/javascript" src="shared/shiny.js"></script> 
    </head> 

    <body> 
     <input type="submit" name="submit" value="Press me!" class="button"> 
     <p><div id="text" class="shiny-text-output" style="width: 150px; height: 25px; border: 1px solid black;"></div> 
    </body> 
</html> 

server.R

shinyServer (function (input, output, session) 
{ 
    observe ({ 
     x = input$button; 

     output$text = renderText ({ 
      if (! is.null (x)) 
      { 
       if (x %% 2 == 0) { 
        "You are even"; 
       } 
       else { 
        "You are odd"; 
       } 
      } 
     }) 
    }); 
}) 

回答

0

您的輸入class需要有一個額外的action-button將其定義爲一個閃亮的綁定類。 你也需要給你的inputid="button"來對應你的電話server.R

<html> 
    <head> 
    <script type="text/javascript" src="shared/jquery.js"></script> 
    <script type="text/javascript" src="shared/shiny.js"></script> 
    </head> 

    <body> 
    <input id="button" type="submit" name="submit" value="Press me!" class="button action-button"> 
    <p><div id="text" class="shiny-text-output" style="width: 150px; height: 25px; border: 1px solid black;"></div> 
    </body> 
</html> 
+0

然後我不需要'class =「按鈕」';我呢? – gaitat

+0

只有當你想要任何與按鈕類相關的CSS – jdharrison