title: Rmarkdown - Add colorbar to table for pdf and html
body: <p>I am trying to add a barplot to a table using Rmarkdown. I got it working for HTML.</p>
  
  <p><strong>The HTML table works perfectly</strong></p>
  
  <pre><code>a &lt;- c(1,2,3)
  b &lt;- c(4,5,6)
  table &lt;- as.data.frame(rbind(a,b)) #Demo table for this example
  summary_column &lt;- c(40,60) #A summary column, showing 40% and 60%.
  
  #add the summary column using background-color
  table[["summary_column"]] &lt;- paste0( 
    "&lt;span style='display: block; border-radius: 4px; padding-right: 4px; background-color: #00457C; color:white; width:",
    summary_column,"%;&gt;", #Size of bar depends on the value of the vector summary_column
    summary_column,"%","&lt;/span&gt;") #The bar has an overlaying valuelabel
  
  library(pander)
  pandoc.table(table) #convert the table to html table
  </code></pre>
  
  <p>Can also be achieved with the formattable package (my code is almost identical to theirs).</p>
  
  <p><a href="https://i.stack.imgur.com/uNzss.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uNzss.png" alt="Result HTML table"></a></p>
  
  <p><strong>My problem is however</strong><br>
  How can I get this barplot to work when I knit to pdf (or Word for that matter)? I don't want to convert the table to an image because I need the interactivity in the table. I thought using an <code>&lt;img&gt;</code> html tag might work for the pdf, but it doesn't (works in HTML however):</p>
  
  <pre><code>table[["summary_column"]] &lt;- paste0( #add summary column
    "&lt;img src='bar.bmp'&gt;") #add the bar.bmp to the column
  </code></pre>
  
  <p>Where bar.bmp is a 5x10px img that I would scale up to X%.<br>
  The pdf will not display background-color nor img.</p>
  
  <p><a href="https://i.stack.imgur.com/fY634.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fY634.png" alt="Resulting table when I knit to pdf"></a></p>
  
  <p>Should I add a column with HTML code for the bar and some Tex code for the bar? My knowledge of Latex is limited.</p>
  
  <p>Is there no way to let the latex engine (xelatex) read css or html tags?</p>
  
  <p>Thank you</p>