TheGreenOne TheGreenOne - 7 months ago 19
HTML Question

How to hide correctly formatted knitr::kable() in html-documents?

I was trying to hide correctly formatted knitr::kable() tables. Without hiding they are looking nice... but if I am showing already hidden tables they appear as normal text.... that's my code so far:

---
title: "Test-Tabellen"
output:
html_document:
theme: cerulean
highlight: textmate
code_folding: hide
---

```{r}
setwd("/Users/AnyName/Desktop/")
```

#####31 elements included exclusively in "Control":
<div id="BE_Genus_C.txt" style="display:none">
```{r cache=FALSE, collapse=TRUE, results='asis'}
test<-read.csv2("BE_Genus_C.txt", header=FALSE, sep="\t")
knitr::kable(test)
```
</div>
<button title="Click to show answer" type="button" onclick="if(document.getElementById('BE_Genus_C.txt') .style.display=='none') {document.getElementById('BE_Genus_C.txt') .style.display=''}else{document.getElementById('BE_Genus_C.txt') .style.display='none'}">Show/hide</button>

Answer

Just adding an extra line after div is enough...

<div id="BE_Genus_C.txt" style="display:none">
```{r cache=FALSE, collapse=TRUE, results='asis'}
test<-read.csv2("BE_Genus_C.txt", header=FALSE, sep="\t")
knitr::kable(test)
```

</div>
Comments