jimhester / knitrBootstrap

A framework to create bootstrap styled HTML reports from knitr Rmarkdown.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

theme & Highlight not working on load + results='asis' not as expected + bootstrap code chunk options not recognized

lcolladotor opened this issue · comments

Hello,

Thank you again for all your work with knitrBootstrap. I've been upgrading derfinderReport (basically, a Rmd file) to your github version of knitrBootstrap and learning all the new options and the like. I feel like it's basically a complete new version, but like you said in #38, this should make it easier for you to maintain it.

Using it, I have however encountered a couple of hiccups as described below.

Theme and highlight not working on load

First of all, regardless of using the YAML front matter or the options in bootstrap_document, the specified theme and/or highlight are now shown on load. They appear as selected as seen below:

screen shot 2014-03-30 at 4 34 41 pm

In this case, I selected the "Brown Paper" highlight option, and you can see that it is selected. If I click on the option again, then it does work. So I'm guessing that a small tweak is missing to make it work from the get-go, instead of relying on the user choosing the option.

As a minor related note, the highlight menu can be too long and not all options will show in the menu as shown below:

screen shot 2014-03-30 at 4 34 55 pm

While the files I'll link at the end do not show this problem for the theme option, I encountered the same problem described above for the highlight option.

results="asis" not as expected

One of the packages that I like to use a lot along with knitrBoostrap is knitcitations (I'm using the CRAN release). While the inline code works well, printing the bibliography doesn't because knitrBootstrap marks the output as "output" when using the code chunk option results='asis' as shown below:

screen shot 2014-03-30 at 4 41 05 pm

It won't let the output be interpreted as markdown syntax, like it should. You can get a very similar result even if you use knitcitations::bibliography(style='html').

bootstrap code chunk options

For some reason, I cannot get some of the knitrBootstrap code chunk options to work. I really like hiding the code by default, and cannot get that work using bootstrap.show.code=FALSE in the code chunk definition or using opts_chunk$set() from knitr.

Note that bootstrap.panel=TRUE does work.

Actually, the options seem to conflict with each other at times. For example, bootstrap.show.output=TRUE, bootstrap.hide=TRUE produces:

screen shot 2014-03-30 at 4 52 00 pm

I would expect the output to be shown in the first chunk (only one with options set) instead of it being hidden.

Then, bootstrap.show.output=TRUE, bootstrap.panel=TRUE, bootstrap.hide=TRUE produces:

screen shot 2014-03-30 at 4 53 19 pm

Similar as above. Here bootstrap.panel=TRUE works as expected.

Finally, bootstrap.show.code=TRUE, bootstrap.hide=TRUE produces:
screen shot 2014-03-30 at 4 56 28 pm

In this case, I would except the code to be shown instead of being hidden.

Overall, it seems to be that it might be best to delete the bootstrap.hide option which seems to create conflicts with bootstrap.show.code and bootstrap.show.output.

Files

I have tested this with both R 3.0.3 and R 3.1.0 using the github versions of rmarkdown and knitrBootstrap. Files were created like this

$ R --vanilla
> library("rmarkdown")
> library("knitrBootstrap")
> render("maps-yaml.Rmd")
> render("maps.Rmd", bootstrap_document(theme.chooser=TRUE, highlight.chooser=TRUE, highlight="Brown Paper"))

I used a slightly modified version of the maps.Rmd vignette.

R 3.0.3

http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.0/maps.Rmd
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.0/maps.html
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.0/maps-yaml.Rmd
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.0/maps-yaml.html

R 3.1.0

http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.1/maps.Rmd
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.1/maps.html
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.1/maps-yaml.Rmd
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-03-30-R-3.1/maps-yaml.html

Thank you!

PS Opening the files in Firefox instead of Chrome shows some console errors. Nevermind, I had an outdated version of Firefox, it works with version 28.0

Also, I don't know if this was intentional, but the color of the output table is different in my output than what you have at http://rawgithub.com/jimhester/knitrBootstrap/master/vignettes/two-D.html

Mine:

screen shot 2014-03-30 at 5 08 12 pm

Yours:

screen shot 2014-03-30 at 5 08 39 pm

Noticed the same issue when trying to embed generated markdown using results='asis' in the latest version of knitrBootstrap.

The code and syntax highlighting is fixed with 445f43e, I added show options for all the chunk output types, which made the hide option unnecessary.

I am not sure what is going on with the results='asis' issues, I have not been able to reproduce them yet, but I will figure it out.

My session info is

R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin12.5.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] igraph_0.6.6         corrplot_0.73        xtable_1.7-1         knitr_1.5.25         rmarkdown_0.1.52
[6] knitrBootstrap_1.0.0 vimcom_0.9-9         setwidth_1.0-3

loaded via a namespace (and not attached):
[1] evaluate_0.5.1 formatR_0.10.3 markdown_0.6.5 stringr_0.6.2  tools_3.0.2

Can either of you post your sessionInfo() so we can see if there is something different there? I don't know how to reproduce the results='asis' bug.

I just tried it again on a different machine after pulling the latest revision from Github, and the issue is no longer present. I will see which commit I was using on the other machine with the issue and let you know, but it looks like it must have been fixed sometime in the past few weeks.

Thank you @jimhester for the quick fixes!

@khughitt, I guess that you are referring to the results='asis' issue. Anyhow, my session information is shown at the end of the html files.

So basically,

## R version 3.0.3 (2014-03-06)
## Platform: x86_64-apple-darwin10.8.0 (64-bit)
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] knitcitations_0.5-0  bibtex_0.3-6         knitr_1.5           
## [4] igraph_0.7.0         corrplot_0.73        xtable_1.7-3        
## [7] knitrBootstrap_1.0.0 rmarkdown_0.1.40    
## 
## loaded via a namespace (and not attached):
## [1] evaluate_0.5.1 formatR_0.10   httr_0.3       markdown_0.6.4
## [5] RCurl_1.95-4.1 stringr_0.6.2  tools_3.0.3    XML_3.95-0.2  
## [9] yaml_2.1.11

and

## R version 3.1.0 beta (2014-03-26 r65301)
## Platform: x86_64-apple-darwin10.8.0 (64-bit)
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] knitcitations_0.5-0  bibtex_0.3-6         knitr_1.5           
## [4] igraph_0.6.5-2       corrplot_0.73        xtable_1.7-3        
## [7] rmarkdown_0.1.28     knitrBootstrap_1.0.0 colorout_1.0-2      
## 
## loaded via a namespace (and not attached):
##  [1] digest_0.6.4   evaluate_0.5.1 formatR_0.10   httr_0.2      
##  [5] markdown_0.6.4 RCurl_1.95-4.1 stringr_0.6.2  tools_3.1.0   
##  [9] XML_3.98-1.1   yaml_2.1.10

I still have the results='asis' problem as shown at

http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/maps-yaml.html
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/maps-yaml.Rmd

I just updated to rmarkdown 0.1.62 and got the same result

R version 3.0.3 (2014-03-06)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] knitcitations_0.5-0  bibtex_0.3-6         knitr_1.5
[4] igraph_0.7.0         corrplot_0.73        xtable_1.7-3
[7] knitrBootstrap_1.0.0 rmarkdown_0.1.62

loaded via a namespace (and not attached):
[1] evaluate_0.5.1 formatR_0.10   httr_0.3       markdown_0.6.4 RCurl_1.95-4.1
[6] stringr_0.6.2  tools_3.0.3    XML_3.95-0.2   yaml_2.1.11

@lcolladotor Did you try latest version of knitrBootstrap from Github?

Yes, I used:

$ R --vanilla

and then

remove.packages("knitrBootstrap")
remove.packages("rmarkdown")
library("devtools")
install_github('rstudio/rmarkdown')
install_github('jimhester/knitrBootstrap')
library("rmarkdown")
library("knitrBootstrap")
render("maps-yaml.Rmd")

Hmm. it might be worth checking to see if the markdown output is correct.

Here is a simple test file ("test.rmd"):

    ```{r results='asis'}
    cat('[test](https://github.com/jimhester/knitrBootstrap)')
    ```

To render it to markdown:

render('test.rmd', 'md_document')

Does the undecorated version show up there? If so, then perhaps it is an issue with the markdown -> html (pandoc) conversion.

pandoc --version
pandoc 1.12.3.3
Compiled with texmath 0.6.6, highlighting-kate 0.5.6.1.
Syntax highlighting is supported for the following languages:
    actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog,
    ...
Default user data directory: /home/keith/.pandoc
Copyright (C) 2006-2013 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.
pandoc-citeproc --version 
pandoc-citeproc 0.3.0.1

Here's the pandoc version information:

$ pandoc --version
pandoc 1.12.3
Compiled with texmath 0.6.6, highlighting-kate 0.5.6.
Syntax highlighting is supported for the following languages:
    actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog,
    clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d,
    diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang,
    fortran, fsharp, gnuassembler, go, haskell, haxe, html, ini, java, javadoc,
    javascript, json, jsp, julia, latex, lex, literatecurry, literatehaskell,
    lua, makefile, mandoc, markdown, matlab, maxima, metafont, mips, modelines,
    modula2, modula3, monobasic, nasm, noweb, objectivec, objectivecpp, ocaml,
    octave, pascal, perl, php, pike, postscript, prolog, python, r,
    relaxngcompact, restructuredtext, rhtml, roff, ruby, rust, scala, scheme,
    sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, texinfo, verilog, vhdl,
    xml, xorg, xslt, xul, yacc, yaml
Default user data directory: /Users/lcollado/.pandoc
Copyright (C) 2006-2013 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.
$ pandoc-citeproc --version
pandoc-citeproc 0.3.0.1

I ran the test.Rmd (see http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/test.Rmd) using:

$ R --vanilla
library("rmarkdown")
render('test.rmd', 'md_document')

to generate http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/test.md which looks ok.

Further using

library("knitrBootstrap")
render('test.rmd', bootstrap_document())

lead to http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/test.html which still has problems with results='asis'

It looks like the markdown output is correct, which suggests that the problem is indeed md -> html conversion.

Is it possible for you to update your version of pandoc? It is already pretty recent, but that would be the first thing I might try.

Once I am home tonight I will check which version of Pandoc, etc. I have and see if that could be related to the issue.

Following https://github.com/jgm/pandoc/wiki/Installing-the-development-version-of-pandoc I installed the newest version of pandoc, but still got the same result. Note that results='asis' does work with pdf output.

I updated (they include the pandoc version info now):

http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/test.Rmd
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/test.md
http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/test.html

and also created the pdf output using

render('test.rmd', 'pdf_document')

http://biostat.jhsph.edu/~lcollado/misc/knitrBootstrap-2014-04-03-R-3.0/test.pdf

Pandoc info summary:

pandoc 1.12.3.3
Compiled with texmath 0.6.6, highlighting-kate 0.5.6.1.
pandoc-citeproc 0.3.0.1

For my system where results='asis' is working, I have:

> sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rmarkdown_0.1.53     knitrBootstrap_1.0.0 setwidth_1.0-3       colorout_1.0-0      

loaded via a namespace (and not attached):
[1] evaluate_0.5.3 formatR_0.10   knitr_1.5.25   markdown_0.6.5 stringr_0.6.2  tools_3.0.3

Versions differ from you on a few things (rmarkdown, markdown, evaluate, etc).

Will check broken setup next.

For reference, here is the working pandoc call:

/usr/bin/pandoc test.utf8.md --to markdown_strict --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.md --filter /usr/bin/pandoc-citeproc --standalone

Ok, I tried updating each of the mismatched packages and in the end using knitr 1.5.25 fixed this.

Also, it works the same using pandoc 1.12.3 and 1.12.3.3

Thanks for the help @khughitt!

Note that I tried updating just evaluate first, didn't work. Updating both markdown and knitr did work, but from https://github.com/rstudio/markdown/blob/master/NEWS I bet that this had nothing to do with markdown 0.6.4 to 0.6.5, and most likely it was related to knitr 1.5 to 1.5.25

Glad you got it working! I checked the machine where it was not working for me, and similarly, it has older version of rmarkdown and knitr. Looks like that was the underlying issue.