jimhester / knitrBootstrap

A framework to create bootstrap styled HTML reports from knitr Rmarkdown.
Other
274 stars 61 forks source link

Allow results='asis' blocks to show by default (even when show_output=FALSE) #15

Closed lianos closed 11 years ago

lianos commented 11 years ago

Many times when I generate *.Rmd reports, I'd like to run knit_bootstrap with show_code=FALSE, show_output=FALSE, show_plot=TRUE since I want the people I'm sharing these with to focus on the results -- the ability to toggle these on/off interactively in the web page is really awesome.

Still, even though I usually (95% of the time) do not want R's output to by shown be default, there are times when I am relying on R's output to be part of the document. A concrete example is when I want to include a tabular result into the web page itself. To do so, I'm using the xtable package to convert data.frames to HTML tables, something like:

```{r result-summary, results='asis', echo=FALSE}
df <- data.frame(a=rnorm(5), b=sample(letters, 5))
print(xtable(df), type="html")


Is there anyway to get `knitr_bootstrap` to be able to have those to show by default even if `show_output=FALSE`? Somehow detect output from `results='asis'` blocks? I guess this is a bit like Issue #2, although I'm yet to see how I can specify the ID of the output in any meaningful way.

To be frank, your ability to detect an output block in your `/* Add div wrapping class to code blocks without them */` javascript section is quite mysterious to me!

Also: This package is insanely great. The ability to set code and output blocks to be globally hidden and toggleable + automatic TOC generation is just awesome ... I `rep("love", Inf)` it.
lianos commented 11 years ago

For what it's worth, the output from print(xtable(df), type="html") leads with a comment banner that let's you know xtable is doing the leg work, eg:

<!-- html table generated in R 3.0.1 by xtable 1.7-1 package -->
<!-- Wed Aug  7 14:01:58 2013 -->
<TABLE ...>
... the table in here ...
</TABLE>

If that'd be helpful ...

jimhester commented 11 years ago

I use the same xtable code blocks to put html tables in my Rmd files as well. knitrBootstrap explicitly wraps any table with a div.output to mark them as output. To remove this functionality just remove the wrap function call. See the following lines.

https://github.com/jimhester/knitrBootstrap/blob/master/inst/templates/knitr_bootstrap.js#L57-L58

I can see your point about not setting them as output though, I will think about it some more to decide whether to remove the wrap by default or not. Thank you for submitting the issue and for using the package, I am glad you like it!