How do I change the font of a Rmd output linked to a shinyapp?

I manage to deploy an app with a download function to create a pdf document. I looked around at different ways of altering the font etc and came up with the following YAML.

output: 
  pdf_document:
    latex_engine: xelatex
mainfont: Arial
fontsize: 12pt
classoption: landscape
geometry: margin=0.5in

This works perfectly on my machine. However, when I deployed the app, I failed to generate the pdf document with the following error on log.

So what should I do on my Rmd file to allow different fonts to be used? I am new to coding in general, so any educational points would be appreciated.

Hi @lawrencelmli,

I believe xelatex is using system fonts (i.e. fonts on your local machine), so is it possible that wherever you are deploying the app does not have the same fonts?

That is what I thought but I tested it on my own laptop after deployment.

An app deployed to shinyapps.io doesn't run on your own laptop, it runs on a server where the font isn't installed, ergo, it doesn't work.

Thanks. Is there another way to change the font settings then?

Try following the advice on this related thread

Sorry I am really new to all of this. Do you mean that all I needed to do is to include the ttf file with my deployment? If yes, :man_facepalming:

Yes, I believe that is what is being suggested in the other thread. Include the font file in the app bundle and refer to it with a relative path from the root dir.

1 Like

I decided to use \fontfamily{} to choose the font to simplify things

1 Like