r - 使用闪亮模块的简单密码设置
问题描述
我能够按照这个解决方案设置一个闪亮的应用程序密码: 在输入密码后启动闪亮的应用程序(使用 Shinydashboard)
现在,我刚刚接触了闪亮的模块,所以我开始想知道是否可以使用模块来制作一个易于设置的密码模块,我可以在我拥有的其他应用程序中实现它。(我使用模块的原因只是了解它。这可以使用常规函数来完成)。
这是我目前的工作解决方案:
##This part of the module is going to set modal's UI
passwordModuleUI=function(id,failed=FALSE){
ns=NS(id)
tagList(
modalDialog(
textInput(ns("username"), "Usuário:"),
passwordInput(ns("password"), "Senha:"),
footer = tagList(
# modalButton("Cancel"),
actionButton(ns("ok"), "OK")
)
)
)
}
#This will load modal UI from observer inside the server
passwordModuleShow=function(ID){
showModal(passwordModuleUI(ID))
}
#This is server side module
passwordModuleEval=function(input,output,session,id,users,passwords){
authenticated <- FALSE
isolate({
Username <- input$username
Password <- input$password
})
Id.username <- which(users == Username)
Id.password <- grep(Password,passwords)
if ((length(Id.username) > 0&nchar(Password)>1) & (length(Id.password) > 0)&nchar(Username)>1) {
if (Id.username %in% Id.password) {
authenticated <- TRUE
removeModal()
} else {
authenticated <- FALSE
}
}
return(authenticated)
}
#This is trying to simplify implementation in shiny apps
setupPassProtection=function(input,output,session,ID,Users,Passwords){
obs1=observe(priority = 1,{
passwordModuleShow(ID=ID)
})
observeEvent(input[[paste0(ID,"ok",sep="-")]],{
if(callModule(passwordModuleEval,ID,users=Users,passwords=Passwords))
{obs1$suspend()}
})
}
my_username=my_password="test"
ui=basicPage(h3("testando passprotect module"))
server=function(input,output,session){
passID="test"
obs1=observe(priority = 1,{
passwordModuleShow(ID=passID)
})
observeEvent(input[[paste0(passID,"-ok")]],{
if(callModule(passwordModuleEval,"test",users=my_username,passwords=my_password))
{obs1$suspend()}
})
}
shinyApp(ui,server)
我想让以下 SERVER 工作,因为它是最简单且可读性更强的版本,而且我可以轻松获取其他功能。
这不起作用:
server=function(input,output,session){
setupPassProtection(input,output,session,ID="test",Users=my_username,Passwords=my_password)
}
感谢有关解决方案或代码简化的任何帮助。
解决方案
推荐阅读
- html - 居中的徽标以及第二行中的导航项目
- google-apps-script - 如何使用谷歌应用脚本在特定范围内从工作表中获取特定图表并将其粘贴到另一张工作表上?
- hive - 如何关闭 Hive 事务
- typescript - 如何修复“缺少类属性转换”
- reactjs - Nextjs 路由器未正确更改页面源
- azure-ad-b2c - 使用经过验证的电子邮件和经过验证的电话的 AAD B2C 注册或登录
- r - 在汇总表中删除空类别组
- android - AS 4.1.3.:对于要导入的每个类,每个 `import Android...` 语句都标记有“无法解析符号 ...”,从而导致许多其他错误
- angular - 使用exceljs将图片设置为Excel
- reactjs - 如何显示更新的状态?