Allow Cross-Origin-Ressource Sharing R-Studio Server/Shiny

大城市里の小女人 提交于 2021-01-29 05:44:35

问题


I am hosting a Shiny App on R-Studio Server. The App created through Shiny is a Browser App. That means JavaScript is executed from the Client site. In my App I create several through user interaction, which are saved on localhost/webserver. I then want to access these files in JavaScript and process them in there. And thats where the trouble starts...

This is cross-origin-ressource-sharing and I cannot make a Cross-Origin XMLHttpRequest since this is forbidden due to security reasons. How am I supposed to access the files in JavaScript? When I pass a relative/absolute path to the files I get

I pass a link like so path/to/file.json and when I check in the console, javascript changes it to something like localhost:numbererOfPort/path/to/file. When I type that into the browser there is nothing. On my filesystem the file is under path/to/file, without the localhost...

Failed to load resource: the server responded http://localhost...json with a status of 404 (Not Found).

I had a look JONSP but I don't think thats what I am looking for since I am not docking onto an API but rather a file, saved on disk. I also tried to loosen the security settings of Chrome by installing an extension that turns on/off CORS. I am still getting this message:

XMLHttpRequest cannot load xy. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.


回答1:


In Shiny, static files (like images, css and javascript files) should be put in the www subfolder under the app folder. These files can then be accessed in Shiny code using relative path (but without www part) or in web browser using http://host_name:port/app_directory/file.name (again without www).



来源:https://stackoverflow.com/questions/38119420/allow-cross-origin-ressource-sharing-r-studio-server-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!