2017-01-29 59 views
0

我想爲R閃亮的web應用程序文件做一個非常簡單的密碼保護。您在下面看到的代碼包含在index.html中。在同一個文件夾中有一個名爲「testflex.html」的文件。這是我想用密碼保護的文件。輸入用戶名和密碼時沒有任何反應。但是,當我輸入WRONG用戶名或密碼時,會顯示錯誤消息。如何通過javascript調用R閃亮的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> 
+1

插件;在user1之後,pass1並嘗試使用==代替=== –

+0

我發現代碼中有幾處錯誤,但無論解決方案是否無效...... Thx無論如何。 –

回答

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) 
+0

謝謝。似乎我應該能夠從閃亮的應用程序腳本本身處理這個問題。今晚我會回家看看它。 –

+0

它適合你嗎? – BigDataScientist

+0

沒有其實它沒有...瀏覽器不會接受,javescript可以打開服務器上的其他文件... –