Problem with generating rmarkdown pdf report with Ukrainian alphabet via shiny app

Hey guys!

I am trying to create shiny app, that produces rmarkdown pdf reports with content depending on user input. Text will be in Latin and Ukrainian alphabet. App works perfectly locally, however hosted on shinyapps.io does not display Ukrainian text.

Minimal example:

App.r

dir.create('~/.fonts') 
f = dir("www")
file.copy(paste("www/",f,sep=""), "~/.fonts")  
system('fc-cache -f ~/.fonts') 
shinyApp(
  ui = fluidPage(
    downloadButton("report", "Generate report")
  ),
  server = function(input, output) {
    
    output$report <- downloadHandler(
      filename = "report.pdf",
      content = function(file) {
        tempReport <- file.path(tempdir(), "report.Rmd")
        file.copy("report.Rmd", tempReport, overwrite = TRUE)
        
        params <- NULL
        
        rmarkdown::render(tempReport, output_file = file,
                          params = params,
                          envir = new.env(parent = globalenv())
        )
      }
    )
  }
)

Report.Rmd

---
geometry: "left=5mm,top=5mm,right=10mm,bottom=5mm"
output:
  pdf_document: 
    latex_engine: xelatex
    extra_dependencies: 
      tikz: null
      enumitem: null
      xcolor: null
      polyglossia: null
      blindtext: null
      rotating: null
      multicol: null
header-includes:
  - \newfontfamily{\cyrillicfont}{Arimo-Regular.ttf}
  - \newfontfamily{\cyrillicfontsf}{Arimo-Regular.ttf}
---

This is text in latin alphabet. 

Це український текст.

If anyone has idea how to make it working on shinyapps.io, I would appreciate.

I suspect there might be an issue with your fonts. You seem to be installing them at the OS level, which is kinda risky as you need to distribute the ttf file. I believe you would be better off with installing them at LaTeX level, via an appropriate font package. Shinyapps.io runs on Ubuntu, which runs on UTF-8 and should not have issues with Cyrillic (I know it handles Czech well, but haven't tried Cyrillic, and your code doesn't run for me).

You may also consider putting the LaTeX code into a template file, I have found it much easier to troubleshoot than YAML. Have a look at this earlier topic on this matter: