Rmd works fine in R but not in shiny

I am running an Rmd script for a pdf document in a shiny app and latex keeps giving the following error:

LaTeX Error: Illegal character in array arg

when I run the Rmd by itself in R Studio (last version) or in R (v.4.0.0) console using render(), everything works just fine.
I have updated MikTex and tinytex and run tinytex::install.tinytex() to no avail.

This is a snippet from the latex log file after Shiny run:


LaTeX Warning: Reference `LastPage' on page 1 undefined on input line 157.

\c@pagesLTS.pnc.arabic=\count294
\c@pagesLTS.double.arabic=\count295
\c@pagesLTS.current.local.arabic=\count296
[1{c:/Users/.../AppData/Roaming/TinyTeX/texmf-var/fonts/map/pdftex/updmap/pd
ftex.map}

 <./www/Logo.png>]

**! LaTeX Error: Illegal character in array arg.**

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.165 ...}[t]{>{\bfseries\leavevmode\color{red}}l}
                                                   
Here is how much of TeX's memory you used:
 12805 strings out of 482401
 195009 string characters out of 5945271
 478335 words of memory out of 5000000
 28335 multiletter control sequences out of 15000+600000
 568887 words of font info for 49 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 44i,15n,45p,1060b,372s stack positions out of 5000i,500n,10000p,200000b,80000s

!  ==> Fatal error occurred, no output PDF file produced

Please advise, Thank you!

Could you create a minimal reproducible example (reprex) of the rmd and shiny app (it's be awesome to have this on rstudio.cloud). Looking up examples of this error, it seems often associated with a table, and so to minimize things, it'd be useful to just give a reprex of the offending code-chunk.

Thank you for the prompt response!

It is probably important to mention that the .Rmd file works perfectly when run directly in RStudio or, when using rmarkdown::render() in R console and runs perfectly from shiny when I suppress the code chunks for long tables, as described further.

Meanwhile I have detected and eliminated one source for this error, such as:

  1. I was using noteMD package to insert text edited with inputAreaText() in shiny and observed that every time a hyphened or bulleted list of text items was used e.g.:

" Our findings show:
1. ldfjaslfklfdj
2. aljeoija
etc."

latex would throw the abovementioned error.

I solved this issue by wrapping the noteMD function with knitr::raw_latex() function in the Rmd file. Code example below:

 knitr::raw_latex(note_in_md_pdf(input$summary))

  1. The second issue refers to long tables (crossing multiple pages).

2.a For the table below:

kable(data1
      , format = 'latex'
      , caption = 'Samples In Study'
      , booktabs = TRUE
      , longtable = TRUE) %>% 

  column_spec(1, bold = TRUE, color = 'red') %>%

  kable_styling(latex_options = c('hold_position', 'repeat_header')) %>%

  kable_styling(font_size = 12)

both tinytex and MikTex throw similar error

! LaTeX Error: Illegal character in array arg.

2.b In the case of another long table the message changes:

I was unable to find any missing LaTeX packages from the error log ReportFulc.log.
! LaTeX Error: Environment longtabu undefined.

The code for the other long table is similar with the one shown above:

kable(data2
        , format = 'latex'
        , caption = 'p-values'
        , align = 'l'
        , booktabs = TRUE
        , longtable = TRUE) %>%

    kable_styling(font_size = 10) %>%

    kable_styling(full_width = TRUE, latex_options = c('repeat_header', 'hold_position')) %>%

    column_spec(1, bold = TRUE, color = 'red')

I have found out which package worked each time by running

for tinytex (having MikTex supressed):

> Sys.which('latex')                                                                latex 
"C:\\Users\\Dragos\\AppData\\Roaming\\TinyTeX\\bin\\win32\\latex.exe" 

for MikTex (tinytex probably still active):

> Sys.which('latex')                                                     latex 
"C:\\PROGRA~1\\MiKTeX 2.9\\miktex\\bin\\x64\\latex.exe" 

And finally:

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] noteMD_0.1.0      xfun_0.14         patchwork_1.0.0   ggplus_0.1        pander_0.6.4     
 [6] gridExtra_2.3     ggpubr_0.3.0      ggplot2_3.3.1     kableExtra_1.1.0  knitr_1.28       
[11] rmarkdown_2.2     RMySQL_0.10.20    DBI_1.1.0         DT_0.13           data.table_1.12.9
[16] shiny_1.4.0.2    

loaded via a namespace (and not attached):
 [1] httr_1.4.1         tidyr_1.1.0        jsonlite_1.6.1     viridisLite_0.3.0 
 [5] carData_3.0-4      cellranger_1.1.0   yaml_2.2.1         pillar_1.4.4      
 [9] backports_1.1.7    lattice_0.20-41    glue_1.4.1         digest_0.6.25     
[13] RColorBrewer_1.1-2 promises_1.1.0     ggsignif_0.6.0     rvest_0.3.5       
[17] colorspace_1.4-1   htmltools_0.4.0    httpuv_1.5.3.1     pkgconfig_2.0.3   
[21] broom_0.5.6        haven_2.3.1        purrr_0.3.4        xtable_1.8-4      
[25] scales_1.1.1       webshot_0.5.2      openxlsx_4.1.5     later_1.0.0       
[29] rio_0.5.16         tibble_3.0.1       farver_2.0.3       generics_0.0.2    
[33] car_3.0-8          ellipsis_0.3.1     withr_2.2.0        magrittr_1.5      
[37] crayon_1.3.4       readxl_1.3.1       mime_0.9           evaluate_0.14     
[41] nlme_3.1-148       rstatix_0.5.0      forcats_0.5.0      xml2_1.3.2        
[45] foreign_0.8-80     tools_4.0.0        hms_0.5.3          lifecycle_0.2.0   
[49] stringr_1.4.0      munsell_0.5.0      zip_2.0.4          compiler_4.0.0    
[53] tinytex_0.23.2     rlang_0.4.6        rstudioapi_0.11    htmlwidgets_1.5.1 
[57] crosstalk_1.1.0.1  labeling_0.3       gtable_0.3.0       abind_1.4-5       
[61] curl_4.3           readtext_0.76      R6_2.4.1           dplyr_1.0.0       
[65] fastmap_1.0.1      shinythemes_1.1.2  readr_1.3.1        stringi_1.4.6     
[69] Rcpp_1.0.4.6       vctrs_0.3.1        tidyselect_1.1.0 

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