首页 > 解决方案 > 在 RShiny 中访问 HTML 单选按钮值

问题描述

我无法从我的 Shiny 应用程序中的 HTML 单选按钮访问值,我非常感谢一些帮助。

这是我的 HTML 代码:

<!DOCTYPE html>

<head>
  <script src="shared/jquery.js" type="text/javascript"></script>
  <script src="shared/shiny.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
  <link rel="stylesheet" href="nostylist.css"/>
</head>

<body>

  <h1>HTML UI</h1>

  <table>
    <tr>
      <th>Statement A</th>
      <th>Agree much more with statement A</th>
      <th>Agree somewhat more with statement A</th>
      <th>Agree somewhat more with statement B</th>
      <th>Agree much more with statement B</th>
      <th>Statement B</th>
    </tr>

    <form>
      <tr>
        <td>I am particular about the food that I eat</td>
        <td><input type="radio" name="row" value="1" checked></td>
        <td><input type="radio" name="row" value="2"></td>
        <td><input type="radio" name="row" value="3"></td>
        <td><input type="radio" name="row" value="4"></td>
        <td>I am not super-picky</td>
      </tr>
    </form>
  </table>

  <label>Number of observations:</label><br />
  <input type="number" name="n" value="500" min="1" max="1000" />

  <h3>Output:</h3>
  <pre id="summary" class="shiny-text-output"></pre>

这是我的 RShiny 代码:

library(shiny)

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$summary <- renderPrint(input$row)
}

# Run the application 
shinyApp(ui = htmlTemplate("www/index.html"), server)

目前,输出的是“NULL”。但是,当我将 input$row 更改为 input$n 时,它引用了我的数字输入,我的数字输入的值得到了很好的输出。关于如何将单选按钮的选定值输出到我的 RShiny 应用程序的任何想法?

这是我的 Shiny 应用程序当前的样子: Shiny App

标签: htmlcssrshiny

解决方案


推荐阅读