Skip to content
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

xelatex rendering issue on shinyapps.io #317

Open
cderv opened this issue Jun 22, 2021 · 4 comments
Open

xelatex rendering issue on shinyapps.io #317

cderv opened this issue Jun 22, 2021 · 4 comments

Comments

@cderv
Copy link
Contributor

cderv commented Jun 22, 2021

Hello everyone. Even though, according to the latest posts, this issue (#205) seems to be solved on shinyapps.io, from my shiny app (deployed there) I am still not able to produce a PDF from an .Rmd file embed in the application if the version of the rmarkdown package is higher than 1.15 and the latex engine is xelatex.

When I have this version installed, everything works fine, even though I get the following warning when the application starts:

This version of bslib is designed to work with rmarkdown version 2.7 or higher

If, however, I try to install the latest version of rmarkdown my PDF report is not produced and I get the following LaTeX error:

! LaTeX Error: Missing \begin{document}.
Warning: Error in : LaTeX failed to compile /var/folders/f9/8lfgdj3d5s1dbzsbtscxg9w80000gp/T//RtmpWVpFWz/file10d19ca31140.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See file10d19ca31140.log for more info. [No stack trace available]

Any idea on how to solve this? Thank you for your help!

Originally posted by @nicocriscuolo in #205 (comment)

@cderv
Copy link
Contributor Author

cderv commented Jun 22, 2021

Hi @nicocriscuolo,

First, about the warning on bslib, are you trying to use bslib ? Or maybe you are using it while using last shiny, this warning is thrown because a very old rmarkdown is used.

Regarding the LaTeX error, have you looked into the log file ?

! LaTeX Error: Missing \begin{document}.

This seems to indicate that there is an issue in the generated tex file. There should be a \begin{document} produce during the conversion from Rmd to .tex by Pandoc when using pdf_document()

I really don't think this is a tinytex issue, but I will leave this issue here for now.

For shinyapps.io supports, know that there are some options: https://shiny.rstudio.com/help/

Anyway, I don't have the answer. I'll asked around. If you can get some more information from log file in the meantime it would be great. It would be interesting to see the version of Pandoc there.

And as always, if you can share a reproducible example, this would greatly help to look into this. Thanks !

@nicocriscuolo
Copy link

Hello @cderv and thank you for creating this new issue for my problem. I've tried to isolate my error, and I found out that this happens in the YAML.

Please find here a minimal reproducible example of my code (adapted to produce just a simple plot). I haven't inserted the code here since the chunks' symbols of R Markdown make it difficult to understand how the code is structured.

When I try to produce the report (also with this simple code) through the shiny application with the 1.15 version of rmarkdown, everything works fine.

However, when I have the 2.9 version of rmarkdown installed, I got the error described in my previous comment. Please find below the logs of my shinyapps.io session to check the pandoc version:

2021-07-08T13:59:53.013350+00:00 shinyapps[1099846]: Starting R with process ID: '43'
2021-07-08T13:59:52.789585+00:00 shinyapps[1099846]: rmarkdown version: 2.9
2021-07-08T13:59:52.780799+00:00 shinyapps[1099846]: Running on host: 7c90a9e03523
2021-07-08T13:59:52.789495+00:00 shinyapps[1099846]: Server version: 1.8.6.1
2021-07-08T13:59:52.789513+00:00 shinyapps[1099846]: LANG: en_US.UTF-8
2021-07-08T13:59:52.789514+00:00 shinyapps[1099846]: R version: 4.0.3
2021-07-08T13:59:52.789567+00:00 shinyapps[1099846]: shiny version: 1.6.0
2021-07-08T13:59:52.789599+00:00 shinyapps[1099846]: knitr version: 1.33.7
2021-07-08T13:59:52.789627+00:00 shinyapps[1099846]: jsonlite version: 1.7.2
2021-07-08T13:59:53.024948+00:00 shinyapps[1099846]: Starting R with process ID: '44'
2021-07-08T13:59:52.789585+00:00 shinyapps[1099846]: httpuv version: 1.6.1
2021-07-08T13:59:52.789890+00:00 shinyapps[1099846]: Using pandoc: /opt/connect/ext/pandoc/2.11
2021-07-08T13:59:53.024947+00:00 shinyapps[1099846]:
2021-07-08T13:59:53.020650+00:00 shinyapps[1099846]: Using jsonlite for JSON processing
2021-07-08T13:59:52.789661+00:00 shinyapps[1099846]: htmltools version: 0.5.1.1
2021-07-08T13:59:52.789653+00:00 shinyapps[1099846]: RJSONIO version: (none)
2021-07-08T13:59:53.804127+00:00 shinyapps[1099846]: Warning: no DISPLAY variable so Tk is not available
2021-07-08T13:59:53.829079+00:00 shinyapps[1099846]: Warning: no DISPLAY variable so Tk is not available
2021-07-08T13:59:56.590033+00:00 shinyapps[1099846]:
2021-07-08T13:59:56.590036+00:00 shinyapps[1099846]: Listening on http://127.0.0.1:45593
2021-07-08T13:59:56.591168+00:00 shinyapps[1099846]:
2021-07-08T13:59:56.591176+00:00 shinyapps[1099846]: Listening on http://127.0.0.1:46238
2021-07-08T14:07:19.523560+00:00 shinyapps[1099846]:
2021-07-08T14:07:19.523561+00:00 shinyapps[1099846]:
2021-07-08T14:07:19.523563+00:00 shinyapps[1099846]: processing file: Country_report.Rmd
2021-07-08T14:07:19.527926+00:00 shinyapps[1099846]:
|
|................................... | 50%
2021-07-08T14:07:19.527303+00:00 shinyapps[1099846]:
|
| | 0%
|
|.................. | 25%
2021-07-08T14:07:19.527475+00:00 shinyapps[1099846]: ordinary text without R code
2021-07-08T14:07:19.527475+00:00 shinyapps[1099846]:
2021-07-08T14:07:19.532033+00:00 shinyapps[1099846]: $ include: logi FALSE
2021-07-08T14:07:19.528902+00:00 shinyapps[1099846]: label: setup (with options)
2021-07-08T14:07:19.583764+00:00 shinyapps[1099846]: ordinary text without R code
2021-07-08T14:07:19.531249+00:00 shinyapps[1099846]: List of 1
2021-07-08T14:07:19.583923+00:00 shinyapps[1099846]:
|
|......................................................................| 100%
2021-07-08T14:07:19.532080+00:00 shinyapps[1099846]:
2021-07-08T14:07:19.584279+00:00 shinyapps[1099846]: label: unnamed-chunk-1
2021-07-08T14:07:19.583765+00:00 shinyapps[1099846]:
2021-07-08T14:07:19.583697+00:00 shinyapps[1099846]:
|
|.................................................... | 75%
2021-07-08T14:07:19.983338+00:00 shinyapps[1099846]:
2021-07-08T14:07:19.984199+00:00 shinyapps[1099846]: output file: Country_report.knit.md
2021-07-08T14:07:19.984199+00:00 shinyapps[1099846]:
2021-07-08T14:07:19.988052+00:00 shinyapps[1099846]: /opt/connect/ext/pandoc/2.11/pandoc +RTS -K512m -RTS Country_report.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output /tmp/RtmpXIRmtq/file2b7b9367ac.tex --lua-filter /opt/R/4.0.3/lib/R/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /opt/R/4.0.3/lib/R/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine xelatex --variable graphics --include-in-header /tmp/RtmpXIRmtq/rmarkdown-str2b31afb3fb.html --variable 'geometry:margin=1in'
2021-07-08T14:07:21.745891+00:00 shinyapps[1099846]: ! LaTeX Error: Missing \begin{document}.
2021-07-08T14:07:21.749594+00:00 shinyapps[1099846]: Warning: Error in : LaTeX failed to compile /tmp/RtmpXIRmtq/file2b7b9367ac.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See file2b7b9367ac.log for more info.
2021-07-08T14:07:21.745893+00:00 shinyapps[1099846]:
2021-07-08T14:07:21.754362+00:00 shinyapps[1099846]: [No stack trace available]

Thank's a lot for your help!

@cderv
Copy link
Contributor Author

cderv commented Jul 8, 2021

Thanks a lot for the example ! I'll have a look

Sharing here the content of the Rmd file so that it is quicker to check this:

---
output:
  pdf_document:
    keep_tex: true
    latex_engine: xelatex
header-includes:
- |
  ```{=latex} 
  \usepackage{microtype}
  \usepackage{fontspec}
  \usepackage{ragged2e}
  \renewcommand{\footnotesize}{\scriptsize \justify}
  \usepackage{setspace}
  \usepackage{xcolor}
  \definecolor{very-light-gray}{gray}{0.95}
  \pagenumbering{gobble}
  \makeatletter
  \def\MT@is@composite#1#2\relax{%
    \ifx\\#2\\\else
      \expandafter\def\expandafter\MT@char\expandafter{\csname\expandafter
                      \string\csname\MT@encoding\endcsname
                      \MT@detokenize@n{#1}-\MT@detokenize@n{#2}\endcsname}%
      % 3 lines added:
      \ifx\UnicodeEncodingName\@undefined\else
        \expandafter\expandafter\expandafter\MT@is@uni@comp\MT@char\iffontchar\else\fi\relax
      \fi
      \expandafter\expandafter\expandafter\MT@is@letter\MT@char\relax\relax
      \ifnum\MT@char@ < \z@
        \ifMT@xunicode
          \edef\MT@char{\MT@exp@two@c\MT@strip@prefix\meaning\MT@char>\relax}%
            \expandafter\MT@exp@two@c\expandafter\MT@is@charx\expandafter
              \MT@char\MT@charxstring\relax\relax\relax\relax\relax
        \fi
      \fi
    \fi
  }
  % new:
  \def\MT@is@uni@comp#1\iffontchar#2\else#3\fi\relax{%
    \ifx\\#2\\\else\edef\MT@char{\iffontchar#2\fi}\fi
  }
  \makeatother
  ```
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
                      warning = FALSE,
                      message = FALSE,
                      fig.pos = "h",
                      dev = "cairo_pdf")
```

```{r}
library(ggplot2)

plot(cty ~ hwy,
     data = mpg)
```

I haven't inserted the code here since the chunks' symbols of R Markdown make it difficult to understand how the code is structured.

Check the issue guide for this: https://yihui.org/issue/#please-format-your-issue-correctly

When I try to produce the report (also with this simple code) through the shiny application with the 1.15 version of rmarkdown, everything works fine.
However, when I have the 2.9 version of rmarkdown installed, I got the error described in my previous comment. Please find below the logs of my shinyapps.io session to check the pandoc version:

I think the Pandoc version used on shinyapps.io will depend on the rmarkdown version you are using. i'll take that into accound while looking deeper into this.

Thanks for the reprex.

@nicocriscuolo
Copy link

nicocriscuolo commented Jul 8, 2021

@cderv, thank you very much for your prompt response and for adapting the code for a GitHub post!

Sorry, but I noticed that for the purpose of this post you can remove the line:

\setmainfont{Times.otf}[BoldFont = TimesBold.otf]

This .otf file is on my local machine.

Thanks a lot for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants