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

如何在R包HTML Vignette及GitHub.io中插入URL图片?

解决R包Vignette在GitHub.io显示图片的问题

核心问题原因

你用的GitHub链接是网页展示链接(含blob路径),不是图片的原始资源地址,浏览器无法直接将其作为图片加载,所以显示空白。

解决方案:使用GitHub原始图片链接

把链接中的blob替换成raw,就能得到可直接访问的图片资源地址:

  • 原链接:https://github.com/tidyverse/ggplot2/blob/main/icons/coord_cartesian.png
  • 修改后:https://github.com/tidyverse/ggplot2/raw/main/icons/coord_cartesian.png

方法1:使用HTML标签

修正你之前的标签错误(应该用<img>而非<src>),替换为raw链接:

<center><img src="https://github.com/tidyverse/ggplot2/raw/main/icons/coord_cartesian.png" alt="coord_cartesian图标"></center>

方法2:使用knitr::include_graphics

在R代码块中使用修改后的raw链接:

url <- "https://github.com/tidyverse/ggplot2/raw/main/icons/coord_cartesian.png"
knitr::include_graphics(url)

额外注意事项

  • 确保GitHub仓库中的图片文件是公开可访问的(私有仓库的raw链接可能需要权限,无法在GitHub.io正常显示)。
  • 本地测试时,raw链接也能正常加载,无需额外配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 14:18:38