限制闪亮字段中的输入类型

Ins*_*nds 4 r data-entry shiny

实际上,numericInput接受字符串和数字输入.如果输入一个字符串,则将其转换为NA(尝试使用下面的代码).有没有办法不允许用户在闪亮的数字字段中键入字符串?

ui <- fluidPage(
  numericInput("num", label = "text not allowed", value = 1),
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderPrint({ input$num })      
}

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

到目前为止,我在数字输入旁边添加了一个文本输出,警告用户如果她在numericInput字段中输入字符串,则只接受数字.这个解决方案对我来说远非理想.

我希望用户无法在数字字段中输入字符值.

Por*_*hop 5

您可以添加validate到表达式中,因此只允许数字输入.我正在使用Windows 7 64位与谷歌Chrome(IE也将工作)

注意:Shiny版本0.13.2,在Firefox上不起作用.

rm(list = ls())
library(shiny)
ui <- fluidPage(
  numericInput("num", label = "text not allowed", value = 1),
  verbatimTextOutput("value")
)
server <- function(input, output) {

  numbers <- reactive({
    validate(
      need(is.numeric(input$num), "Please input a number")
    )
  })
  output$value <- renderPrint({ numbers() })      
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)