-
Hello! I'm having trouble rendering an image when I use the file location as a function argument, but using the same path directly from within the document (the sanity check) works? This reprex assumes you put an image inside ---
title: "Untitled"
---
<style>
.img-container {
height: 300px;
width: 300px;
}
</style>
# Calling image location from a function
```{r}
img_div <- function(src) {
htmltools::tags$div(
class="img-container",
style=sprintf("background-image:url('%s');", src)
)
}
img_div("inst/img/demo.jpg")
```
# Sanity Check
I can see the image here, meaning quarto "knows" that this path exists.
 Is there a way to require assets in the YAML of the file maybe to force having those assets show up? Please note - the image I'm actually using on my site is not hosted on a website, so simply using the image's URL will not work in my use case. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Sorry - the R chunk should end after |
Beta Was this translation helpful? Give feedback.
-
Any reason to not do? ::: {.img-container style="background-image:url('inst/img/demo.jpg')"}
::: Prefer avoiding setting raw HTML inside the document without telling it's raw content. include-in-header:
- text: |
<style>
.img-container {
height: 300px;
width: 300px;
}
</style> |
Beta Was this translation helpful? Give feedback.
-
Hi @mcanouil first of all thanks for your notes and ideas! I put my CSS in a file but just included it inline for the purpose of this reprex but thats good to know for the future!! My use case will be mapping over a bunch of images in a directory so I'd like to avoid calling each one manually in the document if I can, I just kept it to one for the simplicity of the reprex and am also just generally curious why this approach doesn't work |
Beta Was this translation helpful? Give feedback.
-
@MayaGans Which Quarto version are you using ? Are you working in a project ?
Website projects have a way to specify some resource that may not be found automatically by Quarto using the So try add in your YAML resources:
- inst/img/*
If you are using knitr could also have a function that writes raw Markdown ? ```{r}
#| include: false
insert_img <- function(src, cap = "") {
sprintf("", cap, src)
}
```
`r insert_img("inst/img/demo.png")`
Hope it helps |
Beta Was this translation helpful? Give feedback.
@MayaGans Which Quarto version are you using ? Are you working in a project ?
Website projects have a way to specify some resource that may not be found automatically by Quarto using the
resources:
key (https://quarto.org/docs/websites/website-tools.html#site-resources). I believe we probably are not looking into some CSS specified on adiv
to know which resource to include.So try add in your YAML
If you are using knitr co…