R Shiny点击Run App按钮时fileInput报net::ERR_CONNECTION_RESET错误
解决Shiny应用点击RStudio“Run App”时fileInput报net::ERR_CONNECTION_RESET的问题
问题复现
点击RStudio界面的“Run App”按钮启动应用时,fileInput无法正常工作,浏览器控制台提示net::ERR_CONNECTION_RESET;但通过R控制台执行runApp("ui.R", launch.browser = TRUE)时,fileInput功能完全正常。
可能的解决方案
强制指定外部浏览器与固定端口
在shinyApp的配置参数中直接指定启动外部浏览器和固定端口,避免RStudio内置Viewer的连接限制或端口冲突:shinyApp(ui = ui, server = server, options = list(height = 1080, launch.browser = TRUE, port = 8888, # 选一个未被占用的端口 shiny.maxRequestSize = 30 * 1024^2))同时移除全局的
options(shiny.maxRequestSize = ...)和options(shiny.launch.browser = TRUE),确保配置仅作用于当前应用。修改RStudio的“Run App”启动方式
点击RStudio右上角“Run App”旁边的下拉箭头,将“Run in”选项从Viewer Pane改为External Browser。内置Viewer的沙箱机制可能会阻断文件上传的连接请求。清除RStudio缓存
关闭RStudio后,找到对应系统的缓存目录并删除缓存文件:- Windows:
%LOCALAPPDATA%\RStudio-Desktop - macOS:
~/Library/Application Support/RStudio - Linux:
~/.rstudio-desktop
删除目录下的cached_data或temp文件夹,重启RStudio后再测试应用。
- Windows:
更新依赖版本
确保你的R、shiny包和RStudio都是最新版本:# 更新shiny包 install.packages("shiny")同时去RStudio官网下载安装最新版的RStudio客户端,旧版本可能存在已知的连接稳定性bug。
内容的提问来源于stack exchange,提问作者Joran van Noort
相关产品推荐
相关产品推荐

