无法验证闪亮的电子邮件

时间:2017-04-27 15:03:28

标签: r rstudio shiny shiny-server

我使用以下代码验证闪亮应用中的电子邮件地址,但似乎它不适用。

我已将其上传到闪亮的服务器,也许您可​​以尝试在电子邮件列中输入任何内容。

https://brianzhang1994.shinyapps.io/Anqi/

无论您输入什么内容,都不会报告错误。

ui.R:

library(shiny)
shinyUI(fluidPage(
titlePanel("Please Enter Your Info"),
sidebarLayout(
sidebarPanel(
  textInput("firstname","First Name:"),
  textInput("lastname","Last Name:"),
  dateInput("dob","Date of Birth:",format = "mm-dd-yyyy"),
  textInput("numbers","Cell Phone Numers (10 digits):",value = 1111111111),
  textInput("email","Email Address:")
),

mainPanel(
   dataTableOutput("tableforpatient")
)
)
))

server.R:

library(shiny)
isValidEmail <- function(x) {
grepl("\\<[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\>", as.character(x), 
ignore.case=TRUE)
}

shinyServer(function(input, output) {

output$tableforpatient <- renderDataTable({
validate(
  need(input$firstname !="", 
       paste("First Name: Please Input your firstname")),
  need(input$lastname !="", 
       paste("Last Name: Please Input your lastname")),
  need(nchar(as.numeric(input$numbers)) == 10 , 
       paste("Cell Phone Numers: Please Input a 10-digit-number only"),
  need(isValidEmail(input$email),
       paste("Email Address: Please Input a valid E-mail address"))
       )
)
patient <- data.frame(firstname=input$firstname,
                      lastname=input$lastname,
                      dob=input$dob,
                      number=paste0("+1",input$numbers),
                      email=input$email)
})
})

1 个答案:

答案 0 :(得分:1)

您忘了关闭&#34;需要手机号码的支架&#34; need()功能:

need(nchar(as.numeric(input$numbers)) == 10 , 
       paste("Cell Phone Numbers: Please Input a 10-digit-number only")),
need(isValidEmail(input$email),
       paste("Email Address: Please Input a valid E-mail address"))