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 http://rmarkdown.rstudio.com/articles_docx.html).
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,
Laurent
For your information, below you can find an overview of the YAML header
---
author: "John Doe"
date: '`r format(Sys.time(), "%B-%Y")`'
output:
word_document:
toc: true
toc_depth: 4
keep_md: true
reference_docx: mystyle.docx
pdf_document:
toc: true
toc_depth: 4
fig_caption: true
keep_tex: true
html_document:
toc: true
toc_depth: 4
number_sections: true
params:
csv.header: NA
csv.name: 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 = " : ")`'
header-includes:
- \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 :
render('report_name.Rmd',encoding="utf-8",
word_document(reference_docx = "template_name.docx"))
I am having the exact same problem and have tried using word_document() and absolute paths as suggested above, but this has made no difference.
It is odd because it works as expected on rstudio server but not shiny server; even though they are running on the same machine.
I am using absolute paths in with temporary folders, so /tmp/RtmpnWjfwF/oGLv9Kz/template.docx. Could this be causing a problem? Both .Rmd and template.docx are in the same temporary folder.
Sorry for the late reply (especially for bpauget ) and thanks for your help.
A few months ago, I was able to figure out this bizarre behavior. But unfortunately, I could not remember which chunk of code was modified to avoid this issue.
Now, I get it :
In my case, changing the argument output_format from word_document() to "word_document" (char) in the rmarkdown::render() function did the trick.
See printscreen :
rmarkdown::render(..., output_format = "word_document",...) as char : the customized Word template specified in YAML header ("mystyle.docx") is correctly read when compiling the report.
However, when I put the function word_document() in the render function rmarkdown::render(..., output_format = word_document(),...) the template is not read anymore.