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

在HPC计算节点通过VS Code运行R时无法绘图的问题排查

问题:VS Code远程SLURM集群中R绘图无法显示

操作流程

  • 通过Windows笔记本的VS Code SSH连接采用SLURM的机构集群
  • 执行srun --pty -N1 -n1 --mem=4G --time=03:00:00 /bin/bash启动交互式会话(曾尝试添加-X和/或--x11参数)
  • 执行mamba activate r-env激活Conda环境
  • 启动radian(也曾尝试直接启动R),执行plot(1:10)

问题现象

绘图完全无法显示,执行plot(1:10)时抛出错误:

> plot(1:10)
Error in .vsc.browser(httpgd::hgd_url(history = FALSE), viewer = "Beside") : 
  could not find function ".vsc.browser"

直接启动R也会出现相同错误。

相关配置文件

远程机器.vscode-server/settings.json

{
    "gitlens.ai.model": "vscode",
    "gitlens.ai.vscode.model": "copilot:gpt-4.1",
    "editor.formatOnSave": true,
    "typescript.suggest.paths": false,
    "javascript.suggest.paths": false,
    "r.bracketedPaste": true,
    "r.sessionWatcher": true,
    "r.alwaysUseActiveTerminal": true,
    "r.lsp.debug": true,
    "r.rterm.option": [
        "--no-save",
        "--no-restore"
    ],
    "r.libPaths": [
        "/path/from/home/.mamba/envs/r-env/lib"
    ],
    "r.rpath.linux": "/path/from/home/.mamba/envs/r-env/bin/R",
    "r.rterm.linux": "/path/from/home/.mamba/envs/r-env/bin/radian",
    "r.source.focus": "editor",
    "r.plot.useHttpgd": true,
    "files.associations": {
        "*.rmd": "rmd"
    },
    "r.session.levelOfObjectDetail": "Detailed",
    "r.session.objectLengthLimit": 1000
}

本地.Rprofile(曾尝试清空该文件)

# Source - https://stackoverflow.com/a
# Posted by jhat, modified by community. See post 'Timeline' for change history
# Retrieved 2025-11-12, License - CC BY-SA 4.0

if (interactive() && Sys.getenv("TERM_PROGRAM") == "vscode") {
    if ("httpgd" %in% .packages(all.available = TRUE)) {
        options(vsc.plot = FALSE)
        options(device = function(...) {
            httpgd::hgd(silent = TRUE)
            .vsc.browser(httpgd::hgd_url(history = FALSE), viewer = "Beside")
        })
    }
}

SSH配置文件config

Host isg
    HostName XXX
    User YYY
    Port 22
    ForwardAgent yes
    ForwardX11 yes
    ForwardX11Trusted yes
    ServerAliveInterval 60

R环境信息sessionInfo()

r$> sessionInfo()
R version 4.5.2 (2025-10-31)
Platform: x86_64-conda-linux-gnu
Running under: Rocky Linux 9.6 (Blue Onyx)

Matrix products: default
BLAS/LAPACK: /.../.mamba/envs/r-env/lib/libopenblasp-r0.3.30.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: Europe/Madrid
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.5.2

需求

在VS Code连接计算节点时能正常查看R生成的绘图。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 01:50:54