iframe에 반짝이는 앱을로드 할 때 wordpress 로그인 사용자의 사용자 ID를 가져오고 싶습니다. 이 변수는 사용자 별 데이터를 저장하고 수정하는 데 사용될 수 있습니다.
javacript 변수를 앱로드시 shiny/R로 읽음
가 나는 워드 프레스 페이지에 다음 코드를 추가하여 방법의 일부를 입수했습니다 :
<?php global $current_user;
get_currentuserinfo();
$user_name = $current_user->user_login;
$user_ID = get_current_user_id();
?>
그리고 다음이 그것을 자바 스크립트 변수를 만들 :
<script type="text/javascript">
var username = <?php echo json_encode($user_name) ?> ;
var userID = <?php echo json_encode($user_ID) ?> ;
</script>
을
예제를 사용하여 here div 상자를 클릭하면 변수를 가져올 수 있습니다.
ui.R :
library(shiny)
shinyUI(bootstrapPage(
# include the js code
includeScript("get_user_id.js"),
# a div named mydiv
tags$div(id="mydiv",
style="width: 50px; height :50px; left: 100px; top: 100px;
background-color: gray; position: absolute"),
# an element for unformatted text
verbatimTextOutput("results")
))
server.R :
shinyServer(function(input, output, session) {
output$results = renderPrint({
input$mydata
})
})
get_user_id.js :
$(document).ready(function() {
document.getElementById("mydiv").onclick = function() {
document.domain = "DOMAIN_NAME_HERE";
var username = parent.username;
var userID = parent.userID;
Shiny.onInputChange("mydata", userID);
};
});
,
iframe에로드 된 반짝이는 앱이 Wordpress 페이지와 다른 포트에 있기 때문에 도메인 이름 (또는 IP)이 필요합니다. iframe을에 의해 생성해야합니다
<script type="text/javascript">
document.domain = "DOMAIN_NAME_HERE";
</script>
<iframe id="example1" style="border: none; width: 100%; height: 500px;" src="APP_URL" height="150" frameborder="0"></iframe>
하지만 내가 원하는 것은 단지 즉시 응용 프로그램로드 그래서 난에 데이터를 저장하는 응용 프로그램에서 사용할 수있는 변수를 얻을 수 있습니다 데이터베이스 등
나는 이것을 할 어떤 방법을 찾지 못했습니다. 나는 ".onload"또는 내가 시도한 몇 가지 jquery 대안을 사용하여 이것을 달성 할 수 없었다. 어떤 힌트라도 높이 평가 될 것입니다.
편집 : 또한 여기에 게시 : https://groups.google.com/forum/#!topic/shiny-discuss/3XM2mHuzqRs