title: How to get R to output body scripts to format HTML tables using a similar approach as gvisTable?
body: <p>I would like to work out how to generate formatted HTML tables in a way that does not require use of styles that are placed in the HTML header. <a href="https://stackoverflow.com/questions/10842886/how-to-produce-html-tables-and-accompanying-css-using-r-markdown-or-html-sweave">I've broadly asked about this question already</a>, but received one answer that mentioned using the header and another answer that involves using pandoc (<strong>Update: see bottom of this post regarding new answer posted since asking this question</strong>.
  I'd like to have an R function that writes all the HTML formatting required for a formatted HTML table in one place.</p>
  
  <p>I've recently been playing around with <code>gvisTable</code> and it is capable of writing all relevant information in one place:</p>
  
  <p>The following code</p>
  
  <pre><code>```{r results='asis'}
  simpleData &lt;- data.frame(matrix(1:9, nrow=3))
  tab2 &lt;- gvisTable(simpleData, 
                     options=list(width = 600, height = 300))
  print(tab2, "chart")
  ```
  </code></pre>
  
  <p>will output the following into an R Markdown document:</p>
  
  <pre><code>&lt;!-- jsHeader --&gt;
  &lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;
  &lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
  // jsData 
  function gvisDataTableID273f3d05cccd ()
  {
    var data = new google.visualization.DataTable();
    var datajson =
  [
   [
   1,
  4,
  7 
  ],
  [
   2,
  5,
  8 
  ],
  [
   3,
  6,
  9 
  ] 
  ];
  data.addColumn('number','X1');
  data.addColumn('number','X2');
  data.addColumn('number','X3');
  data.addRows(datajson);
  return(data);
  }
  
  // jsDrawChart
  function drawChartTableID273f3d05cccd() {
    var data = gvisDataTableID273f3d05cccd();
    var options = {};
  options["allowHtml"] = true;
  options["width"] =    600;
  options["height"] =    300;
  
       var chart = new google.visualization.Table(
         document.getElementById('TableID273f3d05cccd')
       );
       chart.draw(data,options);
  
  
  }
  
  
  // jsDisplayChart 
  function displayChartTableID273f3d05cccd()
  {
    google.load("visualization", "1", { packages:["table"] }); 
    google.setOnLoadCallback(drawChartTableID273f3d05cccd);
  }
  
  // jsChart 
  displayChartTableID273f3d05cccd()
  
  &lt;!-- jsFooter --&gt;  
  //--&gt;
  &lt;/script&gt;
  
  &lt;!-- divChart --&gt;
  
  &lt;div id="TableID273f3d05cccd"
    style="width: 600px; height: 300px;"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And when this is placed in context, a gvisTable is produced. See <a href="http://rpubs.com/jeromyanglim/simple_gvisTable_example" rel="nofollow noreferrer">the second table in this output</a>.</p>
  
  <p>Thus, a simple R function has outputted all the necessary HTML for the creation of a fairly sophisticated table. Ultimately I'd like to have the same degree of table formatting control seen in LateX, only for R Markdown. And it would be good that given such posts often appear on blogs, through syndication, in RSS readers, and so on that the formatting commands were in the body.</p>
  
  <h3>Questions</h3>
  
  <ul>
  <li>Is it possible to use an approach similar to gvis (e.g., scripts in the HTML body) to format HTML tables (e.g., lines, cell formatting, cell height and width, fonts, etc.)?</li>
  <li>Are there any existing R functions that support the production of such tables?</li>
  <li>Do the assumptions of this question make sense, or is there some other way to achieve my broader aims of precise HTML table formatting with R Markdown?</li>
  </ul>
  
  <h3>Update</h3>
  
  <p><a href="https://stackoverflow.com/a/10893563/180892">Joe has added an answer to my previous question</a> where he mentions three options (style in body; javascript which embeds style in header; and scoped style blocks). So I guess the main question that remains is whether there are any interfaces exist to faciliate using such approaches with R Markdown code blocks.</p>