英文:
Include image in html using R markdown
问题
I have an image named icon.png that I want to put in the title of an html created through RStudio. I got it using this script:
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src="Icon.png" style="float: left;width: 150px;"/>')
});
</script>
My question is related to the path of the image. I just got it by putting the file in the same folder as the .Rmd, but I'd like to load the image from a folder called assets in the same folder as the .Rmd.
- EDA
-- assets - Icon.png
- file.Rmd
Thank you in advance for your help.
英文:
I have an image named icon.png that I want to put in the title of an html created through RStudio. I got it using this script:
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src=\"Icon.png\" style=\"float: left;width: 150px;\"/>')
});
</script>
My question is related with the path of the image, I just got it putting the file in the same folder than the .Rmd...but I'd like to load the image from a folder called assets in the same folder than thr -Rmd
- EDA
-- assets - Icon.png
- file.Rmd
Thank you in advanced for your help
答案1
得分: 1
Option 1:
更改您的 HTML 脚本中的 "img src" 标签。
像下面这样:
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src="assets/Icon.png" style="float: left;width: 150px;"/>')
});
</script>
请注意,使用 HTML 时,您无法引用域根(Web 根)之外的图像文件,请参阅此处:https://webmasters.stackexchange.com/a/48448
Option 2:
您可以使用 Markdown 语法,在这里可以引用位于 .rmd 文件文件夹之外的图像文件。
---
title: my_document_title ![](../asset_out/Icon.png){width=1in}
output: html_document
date: "2023-05-09"
---
英文:
Option 1:
You change the img src
Tag in your html script.
like below
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src=\"assets/Icon.png\" style=\"float: left;width: 150px;\"/>')
});
</script>
Note That with HTML you can't reference image files outside the domain root (web root) see here https://webmasters.stackexchange.com/a/48448
Option 2:
You use Markdown syntax, Note here you can reference image files outside the .rmd file folder
---
title: my_document_title ![](../asset_out/Icon.png){width=1in}
output: html_document
date: "2023-05-09"
---
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论