I do not know whether this fits here. I am basically trying to do some dynamic documents using quarto and typst. but I am not able to pass colours from R code to typst.
The issue is this:
I have penguins.qmd which is parameterised. The qmd file works as expected
and creates a dynamic report which has also some nice colour codes based on
the input parameter. But when I use render.R to create reports for all
species, everything works except the colour coding. I can’t find a way to
do this
Hi @Nithin_M, could you maybe try to revise your post’s title to be a complete question as per the question guidelines:
Good titles are questions you would ask your friend about Typst.
A good title makes the topic easier to grasp, increasing your chances of getting a good answer quickly. We also hope by adhering to this, we make the information in this forum easy to find in the future. Thanks!
I am sorry. Let me explain more. I use quarto along with typst to set template for beautiful reports which i want to make using some R codes. The way to do is using two typst files tyspst-show.typ and typst-template.typ. i use penguins.qmd for my analysis and parameterised reporting. Now since i need this report for three species of penguins in my analysis, i can change my params argument in penguins.qmd to generate report. This works as expected as shown below.
). The report is also colour coded. Now i can use render.R to generate all reports at once. But the issue is although some contents change when we use this approach some contents do not change. as show below
as can be seen color is still of adelie in side bar. also in header it is still adelie. I guess it is beacause of my template issues. Hope i have made my issue clear!
I cloned your repo to try to understand your problem, but couldn’t replicate the error. I am very used to Typst with Quarto but I can’t understand your problem.
What I have found executing render.R is that the color used corresponds to whatever species is hard-coded in penguins.qmd. Try changing it and re-run to see. I would focus my energies into finding what happens then.
Typst seems to be doing its job right, as far as I can see.
No.when using render.R, the colour of plots change but not the sidebar colour. This is not an issue when i am rendering manually by changing params. The issue i find is quarto params is not getting passed to typst variables (species in this case)
There is no Error. Just not the way expected! render.R will generate all required files. The only issue is that colors are not changing when we use render.R but manually when we change params and render that, there is no issue. everything works as expected
Correct. The sidebar colour is the colour of the species entry hardcoded in penguins.qmd. Try changing it or removing it, and you will see the sidebar changing colour to that new species or to the default colour.
I agree that the parameter is not passed to Typst. But it’s not Typst’s fault.
EDIT: In typst-template.typ, replace your line 58 with:
#text(size: 1.6em)[(Colors #species) Species: ]
In penguins.qmd, edit lines 9-10:
params:
species: Default color for sidebar
Then run render.R. You will see what I mean. The colours used are the ones in typst-template.typ, not penguins.qmd.
No. It still does not solve the problem. I know it is not typst problem but my less experience suing typst and quarto together. video
Attaching Video for your reference. As it can be seen, when i manually change params and render i get expected results. Then when the results of render.R is opened, you see only colour of plots change according to species. the inline r code also changes the species, but species controlled by typst is not changing.
I notice that in your repository, penguins_Chinstrap.typ (with the typ extension) is a PDF file. That could be a hint that something is misconfigured in the quarto project? I don’t know, of course, but it can’t be right.
I am not trying to solve the problem at this point but showing you where the problem is by elimination.
How do you pass species from R to Quarto to Typst? That is where it fails. And yes I know it works for the data. It’s just the data is formatted within the Quarto file where the sidebar is formatted within the Typst file.
In the .qmd file, in the header, you would want to receive the .x (containing the current species) from render.R if you understand what I mean. Where you have params: species:.
yes. Based on the discussion given in this link, i figured that params can be used for computation only and not for meta data. So i made a work around like this