【问题标题】:How can I call R shiny html file via javascript?如何通过 javascript 调用 R 闪亮的 html 文件?
【发布时间】:2017-06-15 01:22:37
【问题描述】:

我正在尝试为 R 闪亮的 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>

【问题讨论】:

  • 添加;在 user1,pass1 之后并尝试使用 == 而不是 ===
  • 我看到我在代码中有几个错误,但不管解决方案不起作用......无论如何谢谢。

标签: javascript r shiny shiny-server


【解决方案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)

【讨论】:

  • 谢谢。似乎我应该能够从闪亮的应用程序脚本本身中处理这个问题。今晚我回家后会看看它。
  • 不,实际上它没有...浏览器不会接受 javescript 可以打开服务器上的其他文件...
  • 啊太糟糕了。嗯,另一个想法是通过 R 尝试:browseURL()?
  • 谢谢。会试试的。我曾尝试使用 apache2。 (r-bloggers.com/password-protect-shiny-apps)。我已经设法让 apache 服务器密码正常工作,但也无法让 R Shiny 应用程序运行。
  • 不,它也没有工作......仍然欢迎想法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-12
  • 1970-01-01
  • 2014-04-11
  • 2017-11-03
  • 2020-01-18
相关资源
最近更新 更多