简体   繁体   English

如何在闪亮的应用程序中获取父URL

[英]How to get parent URL in a shiny-app

I embedded a Shiny application with an iframe in my website, and I am now trying to protect my Shiny application : I want the iframe to be reachable only in my website, not directly with its URL. 我在我的网站中嵌入了一个带有iframe的Shiny应用程序,我现在正在尝试保护我的Shiny应用程序:我希望iframe只能在我的网站上访问,而不是直接使用其URL。

  <iframe name="rshiny" 
    src="http://url-of-my-shiny-app/" style="border: none; width: 100%;height:800px;">
  </iframe>  

To do that, I am trying to get the URL of the parent which contains the iframe inside of my Shiny-app, and block it whether it's not the good website. 为此,我试图获取包含我的Shiny-app内部iframe的父级的URL,并阻止它是否不是好网站。

The problem is : I found how to get the URL parent in many languages but R. Does anyone know how I could do it ? 问题是:我发现如何使用多种语言获取URL父级,但是R.有谁知道我怎么能这样做?

I had another possible solution, which doesn't work for the moment : 我有另一个可能的解决方案,暂时不起作用:

postForm('http://url.php', .params = params, curl = curl, style="POST")

I thought I could send a post variable from my website to my R application, like a key, to give the access only to the websites who know the key. 我以为我可以从我的网站向我的R应用程序发送一个post变量,比如一个密钥,只允许访问知道密钥的网站。 But I can't make it work. 但我不能让它发挥作用。

EDIT : I think this question is different from the link suggested in the comments. 编辑:我认为这个问题与评论中建议的链接不同。 Indeed, the suggested option doesn't seem to be usable in R Shiny. 实际上,建议的选项似乎不适用于R Shiny。

I found a solution ! 我找到了解决方案!

Over here, you can find a way to get the "GET" variables in your shiny app. 在这里,你可以找到一种方法来获得闪亮的应用程序中的“GET”变量。 https://github.com/brianbolt/rShinyApps/tree/master/getParameters.shiny . https://github.com/brianbolt/rShinyApps/tree/master/getParameters.shiny In my PHP code, I calculate a md5 password, which depends on the date, to make it change everyday, and I use it as a GET parameter in my iframe : 在我的PHP代码中,我计算了一个md5密码,它取决于日期,每天都要更改,我在iframe中用它作为GET参数:

<iframe name="rshiny" 
    src="youradress?bins=<?php echo $md5password;?">
  </iframe>  

From that point, I can use it directly inside of my code (see input$n_breaks in the code I shared). 从那时起,我可以直接在我的代码中使用它(请参阅我共享的代码中的input$n_breaks )。 I create a reactive function in my server.R, which calculates the same md5 password. 我在我的server.R中创建一个反应函数,它计算相同的md5密码。

In the end, we compare it to the password given in the parameters. 最后,我们将它与参数中给出的密码进行比较。 If it's the same, we open the plots, read the data... Otherwise, we just stop the process. 如果它是相同的,我们打开图表,读取数据......否则,我们只是停止该过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM