javascriptapacheldapshinyshiny-server

get response header variable in Shiny


My apache passes LDAP login to variable X-Remote-User in header:

enter image description here

but I don't know how to get it in Shiny app. Any ideas? Maybe solution could be some java script?


Solution

  • Ok I resolved it. Firstly include in ui.R js function:

    www/js/getLogin.js:

    function requestLogin() {
    var client = new XMLHttpRequest();
    client.open("GET", "yourshinyhostname", true);
    client.send();
    client.onreadystatechange = function() {
        
    var resposne = client.getResponseHeader("X-Remote-User");
    Shiny.onInputChange("getLogin", resposne);
    }; }
    

    Then you can get X-Remote-User value for example by clicking button:

    ui.R:

    includeScript("www/js/getLogin.js"),
    uiOutput("login_btn"),
    verbatimTextOutput("text")
    

    server.R :

    output$login_btn <- renderUI({
      
      HREF <- sprintf('
                      <button id="get_login_btn" value="test" onclick="requestLogin();" >
                      <font color="black">
                      <i class="fa fa-user"></i> Get login
                      </font> 
                      </button>
                      ')
    HTML(HREF)
    }) 
    
    jsOutput <- reactive({
      input$getLogin
    })
    
    output$text <- renderPrint({ 
      jsOutput()
    })