【问题标题】:Match user input from whole csv file R shiny匹配来自整个 csv 文件 R 闪亮的用户输入
【发布时间】:2019-04-10 21:37:32
【问题描述】:

抱歉这个问题我是 R-shiny 的新手 我正在尝试检查用户输入是否在 csv 文件中可用,但它只是匹配 csv 文件的第一行而不是整个 csv 文件列。 我尝试使用数组来检查自己:

output$usignin <- renderUI({
login <- read.csv("check.csv", header = TRUE, na.strings = c("","NA"))
na.omit(login)
asd = match(login$email[3], input$email)
zxc = match(login$password[3], input$password)
if((!is.na(asd)) && (!is.na(zxc))){
  h4("Correct")
}
else{
  h4("Forgot Password?")
}
})

这件事有效,但我希望它动态完成,而不是在login$email[n] 中静态设置数组值。尝试 for 循环对我没有任何其他建议,或者我在使用 for 循环时可能犯了任何错误?

【问题讨论】:

    标签: r shiny rstudio


    【解决方案1】:

    用这么小的代码示例有点难以判断,但这应该可以工作:

    output$usignin <- renderUI({
    login <- read.csv("check.csv", header = TRUE, na.strings = c("","NA"))
    na.omit(login)
    
    asd = match(input$email, login$email)
    zxc = match(input$password, login$password)
    
    test_match <- asd == zxc
    
    if(!is.na(test_match) && test_match){
      h4("Correct")
    }
    else{
      h4("Forgot Password?")
    }
    })
    

    【讨论】:

    • 我试过了,谢谢。但是现在出现的问题是它正在验证用户电子邮件和密码是否不匹配,例如 abc@gmail.com 密码是 12345,并且它正在验证 45678 上的电子邮件,所以现在不应该这样做我该怎么办?
    • 你是什么意思它正在验证 45678 上的电子邮件?
    • 我说例如我的文件包含用户id1: abc@example.com password: 12345id2: def@example.com password: 45678 的 2 条记录,所以如果现在我正在接受用户输入,例如 id:abc@example.com 密码:45678 它正在使这件事正确虽然abc@example.com 的密码是12345
    猜你喜欢
    • 1970-01-01
    • 2017-07-26
    • 2018-09-05
    • 2021-12-17
    • 2020-01-28
    • 2021-01-14
    • 2020-01-16
    • 2015-05-06
    • 2020-12-30
    相关资源
    最近更新 更多