Generating downloadable reports (rmarkdown) : reference_docx (yaml header) is not read by knitr



Hi everyone,

I carry out a Shiny app to generate downloadable reports. User can export the report as a html, pdf or MS Word document as well.
I use another MS Word template that the one provided by default. Hence, I use knitr option "reference_docx" (see Happy collaboration with Rmd to docx

On Rstudio, when I knit the Rmd file, everything works fine: styles are passed from the styles reference docx file to the final docx report but, when I tried to implement this on the shiny app the final report is generated without any style.
It seems that the reference docx is not read.
Yet, reference docx and Rmd file are both in the same directory...

Thank you for your help,


For your information, below you can find an overview of the YAML header

author: "John Doe"
date: '`r format(Sys.time(), "%B-%Y")`'
    toc: true
    toc_depth: 4
    keep_md: true
    reference_docx: mystyle.docx
    toc: true
    toc_depth: 4
    fig_caption: true
    keep_tex: true
    toc: true
    toc_depth: 4
    number_sections: true
  csv.header: NA NA
  csv.quote: NA
  csv.sep: NA
  csv.skip: NA
  csv.asfactor: NA
  csv.encoding: NA
  csv.colnames: NA
  csv.dec: NA
  csv.datapath: NA
  csv.columnsid: NA
  datasite: NA
  fraction: NA
  subset: NA
  longversion: NA
  withaustria: NA
  width.fig: 6
  height.fig: 4.5
  dpi.fig: 300
title: '`r paste("Grimm demonstration of equivalence", params$datasite, sep = " : ")`'
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
- \usepackage{pdfpages}
- \usepackage[utf8]{inputenc}
- \usepackage[T1]{fontenc}
- \usepackage{longtable}
- \usepackage{float}


Hi, Laurent,
I have the same issue...
I just solved it by changing the render function in my server like this :
word_document(reference_docx = "template_name.docx"))

Hoping it will work !