You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

嵌入iframe的Shiny App访问时出现Forbidden权限错误咨询

解决Shiny App嵌入iframe的权限禁止问题

1. 修改Shiny Server配置文件

开源版Shiny Server默认通过X-Frame-Options头禁止页面被嵌入iframe,这就是你遇到权限错误的核心原因。

找到Shiny Server的核心配置文件:

  • Linux环境:/etc/shiny-server/shiny-server.conf
  • Windows环境:Shiny Server安装目录下的conf/shiny-server.conf

打开文件,在对应应用的location块(或全局server块)中添加允许iframe嵌入的响应头配置:

server {
  listen 3838;
  location / {
    site_dir /srv/shiny-server;
    log_dir /var/log/shiny-server;
    directory_index on;
    # 允许你的XAMPP本地页面(http://localhost:80)嵌入
    add_header X-Frame-Options "ALLOW-FROM http://localhost:80";
    # 若要允许所有域名嵌入,替换为:
    # add_header X-Frame-Options "ALLOWALL";
    # 更兼容现代浏览器的写法(推荐):
    # add_header Content-Security-Policy "frame-ancestors 'self' http://localhost:80";
  }
}

2. 重启Shiny Server服务

配置修改后必须重启服务才能生效:

  • Linux:执行sudo systemctl restart shiny-server
  • Windows:打开服务管理器,找到「Shiny Server」服务,右键选择重启

3. 确认iframe代码正确性

检查XAMPP页面中的iframe代码,确保地址指向正确的Shiny App,示例:

<iframe src="http://localhost:3838/your-app-folder-name" width="100%" height="800" frameborder="0"></iframe>

4. 清除浏览器缓存测试

浏览器可能缓存了旧的响应头,建议清除缓存后重新加载页面,或者用无痕模式测试效果。

内容的提问来源于stack exchange,提问作者JobouJP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 03:07:10