我正在尝试为R闪亮的网络应用文件制作一个非常简单的密码保护。您在下面看到的代码包含在index.html中。在同一文件夹中有一个名为“testflex.html”的文件。这是我想用密码保护的文件。输入用户名和密码时没有任何反应。但是,当我输入错误的用户名或密码时,会显示错误消息。
任何提示? (代码如下)
function showPass(form){
var user = form.username.value;
var pass = form.pwd.value;
var user1 = "admin" // this is the username
var pass1 = "abcd1234" // this is the password
if(user === user1 && pass === pass1){
window.open = "testflex.html";
}
else{
document.write("Wrong password or username");
}
}
</script>
<body>
<form>
Username: <input type="text" name="username" /> <br />
Password: <input type="password" name="pwd" /> <br />
<input type="button" value="Log In" onclick="showPass(form)" /> </form> </body>
答案 0 :(得分:1)
有趣的想法。
关于你的问题:
使用window.open("testflex.html")
代替window.open = "testflex.html";
这对我有用:
library(shiny)
openWindow <- '
Shiny.addCustomMessageHandler("resetValue", function(message) {
window.open("new.html");
});
'
# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
tags$head(tags$script(HTML(openWindow))),
selectInput("open", "Class Type:", c(FALSE, TRUE))
),
mainPanel(
textOutput("class")
)
)
))
server <- shinyServer(function(input, output, session) {
global <- reactiveValues(sample = 1:9)
observe({
if(input$open){
session$sendCustomMessage(type = "resetValue", message = "keyVal")
}
})
output$class <- renderText({
print(input$open)
})
})
shinyApp(ui = ui, server = server)