【问题标题】:prompt multiple choice to user R提示用户 R 进行多项选择
【发布时间】:2015-10-27 09:29:59
【问题描述】:

我有一个包含场景的数据框

number  var1  var2
  1     "a1"  "b1"
  2     "a1"  "b2"
  3     "a2"  "b1"
  4     "a2"  "b2"

我想通过询问用户他想要的价值来找到场景编号

var1 / var2

我不认为它可以与

readlines

要求用户写一些东西。

我想要类似的东西

"What value of var1?"
1. "a1"
2. "a2"

而用户只需选择 1 或 2。这很难吗?

【问题讨论】:

  • x <- as.numeric(readline('What value of var1? \n 1. "a1" \n 2. "a2" \n')) 之类的开头。
  • 我猜对我来说,够了!谢谢。

标签: r prompt choice


【解决方案1】:

在 R 中制作一个闪亮的小应用程序。查看http://shiny.rstudio.com/gallery/ 中的一些示例

这是一个下拉框的示例。

library(shiny)
shinyApp(
  ui = fluidPage(
    selectInput(
      "select", 
      label = h3("Select box"), 
      choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), 
      selected = 1
    ),
    hr(),
    fluidRow(column(3, verbatimTextOutput("value")))
  )
  server = function(input, output) {
    # You can access the value of the widget with input$select, e.g.
    output$value <- renderPrint({ input$select })
  }
)

【讨论】:

  • 我使用了另一个更简单的建议来满足我的适度需求,但会记得看看这个。谢谢
  • 我同意这需要更多的工作。但是你会得到一个更加用户友好的环境。很大程度上取决于最终用户对 R 的了解程度。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-28
  • 2017-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多