在 R markdown 中折叠/隐藏数字 [英] Collapsing / hiding figures in R markdown
问题描述
在我的 rmarkdown 文档中,我可以使用以下内容显示和隐藏代码 - 这会在每个代码块之前的文档右侧创建一个方便的按钮:
In my rmarkdown document, I am able to show and hide code with the following - which creates a convenient button on the righthand side of the document before each block of code:
output:
html_document:
code_folding: hide
有没有类似的方便的方法来隐藏表格或图形?如果是这样,请提供参考,因为我找不到任何参考.否则将不胜感激,谢谢!
Is there a similarly convenient method to hide tables or figures? If so, please provide a reference as I have not been able to find any. Otherwise a workaround would be appreciated, thank you!
推荐答案
如果您将此添加到 .Rmd
文件的末尾
If you add this to the end of your .Rmd
file
<script>
$( "input.hideshow" ).each( function ( index, button ) {
button.value = 'Hide Output';
$( button ).click( function () {
var target = this.nextSibling ? this : this.parentNode;
target = target.nextSibling.nextSibling.nextSibling.nextSibling;
if ( target.style.display == 'block' || target.style.display == '' ) {
target.style.display = 'none';
this.value = 'Show Output';
} else {
target.style.display = 'block';
this.value = 'Hide Output';
}
} );
} );
</script>
然后在你想要切换的每个块之前:
and then this before each chunk you want to have a toggle:
<input type=button class=hideshow></input>
(改编自此处:https://groups.google.com/forum/#!topic/knitr/d37E0mP3w6k)
注意:如果您显示代码,这将起作用 - 如果您隐藏代码(使用 echo = FALSE
),请更改
Note: this will work if you show the code - if you are hiding the code (with echo = FALSE
), change
target = target.nextSibling.nextSibling.nextSibling.nextSibling;
到
target = target.nextSibling.nextSibling;
注意2:如果要使用code_folding
选项,改
Note 2: if you want to use the code_folding
option, change
target = target.nextSibling.nextSibling.nextSibling.nextSibling;
到
target = target.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling;
这篇关于在 R markdown 中折叠/隐藏数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!