![](/img/trans.png)
[英]How can I get a button in Shiny to call both JavaScript and R code in parallel?
[英]How can I call R shiny html file via javascript?
我正在尝试为R Shiny Web应用程序文件提供非常简单的密码保护。 您在下面看到的代码包含在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>
有趣的主意。 关于您的问题:使用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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.