Search code examples
r-markdownreportworkflowbioinformaticssnakemake

Snakemake report with Rmarkdown and custom.css file


Below an example of Snakemake Rmd report with a custom.css.

---
title: "Test Report"
date: "`r format(Sys.time(), '%d %B, %Y')`"
params:
   rmd: "report.Rmd"
output:
  html_document:
     css: "custom.css" 

---

## R Markdown

This is an R Markdown document.
Test include from snakemake `r snakemake@input`.

This specific example does not work because Snakemake moves the .rmd file to a temporary location.

File custom.css not found in resource path
Error: pandoc document conversion failed with error 99

The trivial solution would be moving the custom.css to where report.rmd is rendered, but we don't have this location. In addition, we can not use the snakemake directive on the header, as it is only available after it.

Does anyone have a solution for this issue? The only solution I can think is patching Snakemake to accept specific header parameters.


Solution

  • Snakemake object is not available Rmd preamble (see here).

    The solution I found was to use a css chunk instead of the CSS parameter:

    ---
    title: "Test Report"
    date: "`r format(Sys.time(), '%d %B, %Y')`"
    params:
       rmd: "report.Rmd"
    output:
      html_document
    ---
    
    ```{css, echo=FALSE}
    .Sidebar {
       background-image: url('logo.png');
    
    ```
    
    ## R Markdown
    
    This is an R Markdown document.
    Test include from snakemake `r snakemake@input`.
    

    Although this works fine for my use case, I think it would be helpful to have the snakemake object in the preamble.