-
Notifications
You must be signed in to change notification settings - Fork 336
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I use R variables in quarto YAML? #1391
Comments
Hi, in theory, you have to use the keyword |
I tried it and it does not work as for
produced an error:
|
Nope --- I've tried again. I can specify in my YAML
but what happens is that the footer is parsed "verbatim", so it appears as
but the text is parsed correctly in the slide body (so it turns the object I don't know if there's an issue with how the
and that works perfectly. But then I would need to copy the same text for each slide, which is obviously not ideal... Any suggestions? Many thanks again! |
You can't mix expression and string, it's one or the other. |
Interesting --- it works if you do
(so enclosed in quotes). But it fails if you try with |
If I try your suggestion, the resulting footer is processes but not rendered as I would like, ie it is like this:
(It does also work with
This makes me think that the problem is with
in the yaml)? |
In a way, the
The latter is why With Quarto, the logic is quite similar: knitr inline code chunk can't be used as fields will be processed by Quarto directly. So yes, for now, I am not sure it is possible to use Quarto introduces Variables (https://quarto.org/docs/authoring/variables.html#var) that can be used in YAML fields too, only in projects for now though: #1252 Did you already tried using variables ? But in short, to answer your issue question: "Can I use R variables in quarto YAML?", the answer is no you cannot use R variables as Quarto will need the value of the variable and the YAML header is not processed by knitr. Maybe we can find a way to make params accessible as variables though ? Or at least improve using parameterized YAML value . |
Thank you for this. I'll look at the summary you mention and the other bits and pieces. I guess the specific question is probably a bit wider than the reason why I asked it, which is in fact: "can I construct the footer in a quarto presentation by combining elements from the yaml?" In a way, the answer to this is yes --- I have done it, but this means having to replicate the footer on each slide... It is probably beyond my understanding/knowledge of reveal/javascript/html/css/scss etc, but I guess there probably are ways to "inject" this compiled code onto every slide? I made a comment on #809 last night --- I was trying to hack a function that can be used for I wonder whether something similar could be used for the footer issue? |
With shortcodes and meta (https://quarto.org/docs/authoring/variables.html#meta) you can almost do the footer part, but I can't retrieve the author name ... |
You mean the div solution shown in #1391 (comment) ? Are the value in You could also leverage Lua filters to add some component in each slides (https://quarto.org/docs/extensions/filters.html).
Lua filters could be the solution, otherwise some JS inserted in header to remove the logo when class is detected. But the latter would be done in browser and not before the documented is rendered to HTML. |
@mcanouil this is because Maybe this is a bug also and we don't put back the author field to be accessible in the meta shortcode. If you build a simple reproducible example with html format, you can open a new issue. |
Thanks --- that's helpful. I think the issue is that you can only use "standard" fields in the For instance, I've created a separate
and defined a suitable class
( @cderv: yes I meant #1391 (comment). When I create that footer, all works well. I haven't played with |
@giabaio I just want to add that you are not really using the parameters feature by using Regarding parameters, this is supposed to be used this way : ---
title: "My Document"
params:
alpha: 0.1
ratio: 0.2
---
```{r}
params$alpha
```
The ratio is `r params$ratio` Same as with R Markdown: https://bookdown.org/yihui/rmarkdown/params-use.html but also working for Jupyter in Quarto. Regarding you title page, that is clever. |
Thank you! I am still learning about quarto and had no idea about This
does exactly what I want (I've defined suitable fields There are only two immediate little nuisances (which again may be due to me not knowing full well what I'm doing...):
Many thanks for your help on this! |
This would require a specific reproducible example to look into it closer.
EIther
or
works. or you could just use
Usually Probably the setting
|
Thanks again! Using |
Thanks again for all your help. This should have the files for a minimal reproducible example. When you compile the presentation, it opens the title page with the footer. After you navigate out of the title page and go back, the footer won't show on page 1 any more... Everything else, I think I should have fixed, wrt what I was originally asking in the last couple of days. Many thanks for your support! |
Why do you have a empty footer in I believe by doing this you are saying you want no footer (empty footer). To me the issue is that at first when opening the presentation, the footer should be empty. (which is not because we are adding a hook regarding footer on slide change, which does not happen when first opening the presentation). Car you clarifying the behavior you are expecting ? |
Sorry --- I probably wasn't very clear... Yes: I do want to specify a footer that should appear from slide 2 onwards (but not on slide 1). I thought I needed to overrule the general
statement in the yaml, by explicitly saying something in the title-slide? Sorry --- I hope this is clearer? |
Yes this is clearer, and I think this may be a bug. For now you could add a JS script in your presentation that would add I need to see closer as by design we are expecting footer on title slide, but allow to remove on other slides. |
Thank you @cderv. I don't expect you to do it for me, of course, but I'm not too sure how I would write the JS script... Do you mean something like the
I've tried to hack that, but this doesn't work (mostly because I don't know what I'm doing, of course... :-) ). I'll keep at it, though it's a relatively minor issue, TBF and, for now, I can certainly live without it... |
Sorry I forgot that footer was like Logo or page number and it is not that straightforward. You can adapt what I did there: #557 (comment) Something like: ---
format:
revealjs:
footer: Custom footer
include-after-body:
text: |
<script type="text/javascript">
Reveal.on( 'ready', event => {
// remove footer when prez start on first slide
if (event.indexh === 0) {
document.querySelector("div.footer").style.display = "none";
}
})
Reveal.addEventListener('slidechanged', (event) => {
// Aslo remove footer when prez start go back to first slide
if (event.indexh === 0) {
document.querySelector("div.footer").style.display = "none";
}
});
</script>
---
# Slide 1 {#title-slide}
# Slide 2
content Hopefully with not to much side effect as Quarto should handle putting the correct footer on all other slides. |
Thank you, @cderv. This seems to work --- though like you say it probably would be nice to have some more built-in command. I hope this is useful feedback and doesn't sound like constant whining (:wink:), but both footer and logo do appear on the title slide, they just are sort of deleted almost immediately, rather than being taken out altogether?... Thanks again! |
Exactly. They are included by hidden in browser once slides are loaded. There is currently no other way to "not include" footer div in slides |
OK! Thanks. |
Can I possibly continue to be very dumb and ask why the following doesn't work?
When I use
(which I think selects all slides because the whole presentation is wrapped in a BTW: I may be wrong/mistaken here, but I have defined the class
but the resulting html file wraps it around a |
I think (not tested the code) the "error" is coming from the wrong key used in your yaml:
instead of
Also you could use the |
Actually, I think I figured it out.
--- this does exclude the logo from the title slide, which is embedded in a |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I may be missing something obvious, but I would like to do that. I'm working on a quarto slide presentation (formatted in revealjs) and I have defined a bunch of objects in the
params
variable in my YAMLWhat I would like to do is to use the elements of
params
to feed to thefooter
that I want to use for the slides, something likebut it seems like I can't use the
tag inside the yaml, as it returns an error
Like I said, it's possible I am not doing this right --- but can anyone explain why and how I can do it instead?
Thanks
Gianluca
The text was updated successfully, but these errors were encountered: