Hi everybody!

Is it possible that shinyapps.io does not support any other Latex rendering engines than pdfLatex?

For a Shiny app that renders rmarkdown documents with unicode characters, I want to use the xelatex or the lualatex latex engine. As soon as I define one of these engines in the YAML header of the rmarkdown file, the rendering of the rmarkdown file crashes when triggered in a Shiny app running on shinyapps (it works locally as well as on RStudio Connect).

So I create two rmarkdown files, one with pdflatex (default) and one with lualatex latex rendering engine:

lualatex.Rmd:

---
output:
   pdf_document:
     latex_engine: lualatex
---

Hello! This is lualatex.

pdflatex.Rmd:

---
output:
   pdf_document:
     latex_engine: pdflatex
---

Hello! This is pdflatex.

Then I create a super-simple Shiny app with two download buttons, both triggering rmarkdown::render() - once for the pdflatex, and once for the lualatex rmarkdown file:

app.R:

library(shiny)

ui <- fluidPage( 
    downloadButton("button_pdflatex", label = "Pdflatex"),
    downloadButton("button_lualatex", label = "Lualatex")
)

server <- function(input, output) {    
    # Pdflatex engine
    output$button_pdflatex <- downloadHandler(
        filename = function() {
            "pdflatex.pdf"
        },
        content = function(con) {
            rmarkdown::render("pdflatex.Rmd",
                              output_file = con,
                              envir = new.env())
        }
    )
    
    # Lualatex engine
    output$button_lualatex <- downloadHandler(
        filename = function() {
            "lualatex.pdf"
        },
        content = function(con) {
            rmarkdown::render("lualatex.Rmd",
                              output_file = con,
                              envir = new.env())
        }
    )
}

shinyApp(ui = ui, server = server)

When I run this app locally, it works perfectly clicking both buttons. When I deploy it on our Company's RStudio Connect server, also works perfectly.
When I try to deploy it to shinyapps, the pdflatex works, but the lualatex fails with the following error message (out of the shinyapps logs):

2020-03-27T15:56:55.427658+00:00 shinyapps[1998917]: processing file: lualatex.Rmd
2020-03-27T15:56:55.428687+00:00 shinyapps[1998917]:   ordinary text without R code
2020-03-27T15:56:55.428687+00:00 shinyapps[1998917]: 
2020-03-27T15:56:55.428784+00:00 shinyapps[1998917]: 
2020-03-27T15:56:55.429249+00:00 shinyapps[1998917]: output file: lualatex.knit.md
2020-03-27T15:56:55.429250+00:00 shinyapps[1998917]: 
2020-03-27T15:56:55.430641+00:00 shinyapps[1998917]: /opt/connect/ext/pandoc2/pandoc +RTS -K512m -RTS lualatex.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output /tmp/RtmpsdeVi1/file183a17fb39.tex --self-contained --highlight-style tango --pdf-engine lualatex --variable graphics --lua-filter /opt/R/3.6.3/lib/R/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /opt/R/3.6.3/lib/R/library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in' 
2020-03-27T15:56:56.320490+00:00 shinyapps[1998917]: cannot setup TLPDB in /home/shiny/texmf at /usr/bin/tlmgr line 5604.
2020-03-27T15:56:56.323812+00:00 shinyapps[1998917]: Warnung in system2("tlmgr", args, ...)
2020-03-27T15:56:56.323814+00:00 shinyapps[1998917]:   Ausführung von Kommando ''tlmgr' search --file --global '/unicode-math.sty'' ergab Status 2
2020-03-27T15:56:56.325065+00:00 shinyapps[1998917]: ! LaTeX Error: File `unicode-math.sty' not found.
2020-03-27T15:56:56.325067+00:00 shinyapps[1998917]: 
2020-03-27T15:56:56.325067+00:00 shinyapps[1998917]: ! Emergency stop.
2020-03-27T15:56:56.325068+00:00 shinyapps[1998917]: <read *> 
2020-03-27T15:56:56.327356+00:00 shinyapps[1998917]: Warnung: Error in : LaTeX failed to compile /tmp/RtmpsdeVi1/file183a17fb39.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See file183a17fb39.log for more info.
2020-03-27T15:56:56.325069+00:00 shinyapps[1998917]: 
2020-03-27T15:56:56.332635+00:00 shinyapps[1998917]:   [No stack trace available]

Trying it with xelatex, a similar error appears. I don't understand that error message - how could I somehow incorporate unicode-math.sty. Thank you so much for your help!

Funny timing, I just deployed a shiny application online that renders a PDF using xelatex, and found out the hard way that xelatex isn't supported on shinyapps.io. I was only using xelatex in order to use fontspec to change fonts. So I resorted back to commands that were kosher with pdflatex.

I believe xelatex and lualatex aren't supported for the Ubuntu version that they use on the servers. Hope this is somewhat helpful.

Hmm, that is really unfortunate. Then I will also have to make use of pdflatex somehow too. That will be rather difficult, as I print a string received by an API that can contain special unicode characters which I cannot foresee, so \usepackage[utf8]{inputenc} together with \DeclareUnicodeCharacter{...} does not do the trick. Thank you for the answer!

1 Like

Apparently the rendering of Rmarkdown with lualatex/xelatex output works, when a simple template .tex file is referenced in the YAML header of the Rmarkdown:

template.tex:

\documentclass[12pt,a4paper,oneside]{article}
\begin{document}
$body$
\end{document}

lualatex.Rmd :

---
output:
   pdf_document:
     template: template.tex
     latex_engine: lualatex
---

Hello! This is lualatex

I do not understand why this would work, but it does.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

@josh I'm not sure if you are the right person to ask, but do you know which LaTeX distribution we use on ShinyApps.io? I have received multiple reports on the missing unicode-math.sty: https://github.com/yihui/tinytex/issues/205 If we are using TinyTeX, we need to preinstall the LaTeX package unicode-math (tlmgr install unicode-math). If we installed TeX Live (via apt or something like that), we may need to install a certain texlive-* package.

For reference, this issue should be fixed now on shinyapps.io.

1 Like