【问题标题】:Shiny dynamic button press error闪亮的动态按钮按下错误
【发布时间】:2014-07-03 02:20:04
【问题描述】:

如果我按下按钮的次数是偶数还是奇数,我希望这段代码能写出来?相反,什么也没有发生。

我的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";
                }
            }
        })
    });
})

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    输入中的class 需要有一个额外的action-button 才能将其定义为闪亮的绑定类。 您还需要将input 提供给id="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>
    

    【讨论】:

    • 那我不需要class="button";我呢?
    • 仅当您想要与按钮类关联的任何 css 时
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 2018-08-01
    • 2021-12-05
    • 2018-09-25
    • 1970-01-01
    相关资源
    最近更新 更多