I would like to try to produce reports (pdf and probably html) in jupyter using R kernel. However, I would like to hide code in two ways, depending on audience:
When I have looked for this I found answers for python kernel. Is there a way to this in R (no python code)?
So I have started to combine python's answer: How to hide code from cells in ipython notebook visualized with nbviewer? with How to render LaTeX / HTML in Jupyter (R)? and it works. If one puts the following code in a cell, will get a button for hiding code. From here I think I know where to start.
library(IRdisplay)
display_html(
'<script>
code_show=true;
function code_toggle() {
if (code_show){
$(\'div.input\').hide();
} else {
$(\'div.input\').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()">
<input type="submit" value="Click here to toggle on/off the raw code.">
</form>'
)
As you're talking about making HTML and PDF reports, you can do this by using a custom template with nbconvert, and using that to hide cells. This will work for any notebook, independent of the kernel you use.
Docs on nbconvert templates: http://nbconvert.readthedocs.org/en/latest/customizing.html
Examples including hiding code cells based on cell metadata: https://github.com/jupyter/ngcm-tutorial/tree/master/Day-2/nbconvert_templates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With