[英]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.