Created
March 16, 2015 18:45
Add "Show R code" checkbox to .Rmd files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Some custom CSS styles --> | |
<style> | |
.title{ | |
font-size: 3em; | |
} | |
body, td { | |
font-family: sans-serif; | |
background-color: white; | |
font-size: 16px; | |
} | |
h1 { | |
font-size:1.8em; | |
} | |
h2 { | |
font-size:1.4em; | |
} | |
/* Hide codeboxes initially*/ | |
.codebox { | |
display:none; | |
} | |
/* Aligns codebox and "Show R-code"*/ | |
input[type=checkbox] { | |
float: left; | |
margin-right: 0.4em; | |
} | |
</style> | |
<!-- Code highlighting --> | |
<script type="text/javascript"> | |
$(window).load(function() { | |
$('pre code').each(function(i, block) { | |
hljs.highlightBlock(block); | |
}); | |
}); | |
</script> | |
<!-- This is the hideable box with the R code --> | |
<!-- You need a *unique* id for the div with class "codebox" (e.g., code1) AND another unique id for the code block (e.g., code1X). Change these for every additional code box--> | |
<!-- Otherwise the checkbox will close other codeboxes as well --> | |
<input type="checkbox" onChange="$('#code1').toggle('slow');" />Show R-Code<br /> | |
<div id="code1" class="codebox"><pre class="r"><code id="code1X" class="r"> | |
<script type="text/javascript">$(document).ready(function(e) {$('#code1X').load('Presidents-Correlation.R');});</script> | |
</code></pre></div> | |
<!-- This is the actual computation; refers to the same external R file --> | |
```{r code_snippet1, echo=FALSE, message= FALSE, warning= FALSE} | |
source("Presidents-Correlation.R") | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment