title: Putting tables automatically in tabs in Rmarkdown
body: <p>I want to put tables produced from a <code>for()</code> loop in different tabs automatically. I used the code below from <a href="https://stackoverflow.com/questions/43752095/programmatically-insert-header-and-plot-in-same-code-chunk-with-r-markdown-using">similar code for plots</a></p>
  <p>but it doesn't work properly for tables. It creates the tabs but doesn't show the tables in them. Could anyone please correct my code?</p>
  <pre><code>---
  output: html_document
  ---
  
  # title 1 {.tabset}
  There should be one table in each tab. 
  
  ```{r echo=FALSE, warning=FALSE, results='asis'}
  for(Species in levels(iris$Species)){
    cat('\n##', Species, '\n')
    p &lt;- iris[iris$Species == Species,]
    knitr::kable(p)
    cat('\n')
  }
  ```
  </code></pre>
  <p><img src="https://i.stack.imgur.com/EsAOu.png" alt="The image shows my output; No table!" /></p>