GithubHelp home page GithubHelp logo

jimhester / knitrbootstrap Goto Github PK

View Code? Open in Web Editor NEW
273.0 28.0 61.0 20.43 MB

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

License: Other

R 1.19% Perl 0.13% CSS 0.51% JavaScript 0.24% Makefile 0.06% HTML 97.86%

knitrbootstrap's Introduction

Knitr Bootstrap

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

Table of Contents

Features

  • Uses bootstrap 3.0, should work for all screen sizes.
  • Automatic table of contents constructed from h1-4 tags.
  • Images are automatically centered, thumbnailed and lightboxed using magnific popup.
  • Style with themes from bootswatch, optionally including a dynamic style switch.
  • Code blocks automatically highlighted using highlight.js, optionally including a dynamic style switch.
  • Code/Output block and plot visibility can be toggled with a mouse click
    • Globally
    • Per language
  • Create completely offline reports, including all css, javascript and images
  • Mathematical equations using mathjax, note this does not work offline

Examples

All the examples include a css style switch, so you can try out the various styles from bootswatch.

  • 2d - examples of miscellaneous 2d
  • cars - using ggplot2 and the cars dataset
  • engines - using other language engines
  • illusions - examples of interesting optical illusions
  • maps - examples of map plots, and holding plots until end of the block
  • math - examples of MathJax formulas
  • all - All examples together

Installation

If you want to install the latest development version use the devtools package to install the rmarkdown and knitr (devel) prerequisites and this package.

library(devtools)
install_github('rstudio/rmarkdown')
install.packages('knitr', repos = c('http://rforge.net', 'http://cran.rstudio.org'),
                 type = 'source')
install_github('jimhester/knitrBootstrap')

You can install the latest released version from CRAN. Typically lags behind latest by a good amount.

install.packages('knitrBootstrap')

Usage

Knitr Bootstrap includes a knitrBootstrap::bootstrap_document custom rendering function for use with the Rmarkdown package.

RStudio

Very current versions of RStudio use the render function when you press the "Knit" button. In order to output using knitrBootstrap use the YAML front-matter in your document.

YAML Front-matter

You can also specify the bootstrap_document function as an output type along with the options in the YAML front-matter directly in your Rmd file. All of the global Package Options can be specified in the front matter.

---
output:
  knitrBootstrap::bootstrap_document:
    title: "Test file"
    theme: amelia
    highlight: sunburst
    theme.chooser: TRUE
    highlight.chooser: TRUE
---

Render Function

You can also simply call the render function by itself.

library(knitrBootstrap)
library(rmarkdown)
render('file.Rmd', 'knitrBootstrap::bootstrap_document')

Vim

Using the Vim-R-Plugin put the following function in your .vimrc to create the file directly with knitr and the markdown package

function! RMakeHTML_2()
  update
  call RSetWD()
  let filename = expand("%:r:t")
  let rcmd = "require('knitrBootstrap');\
    render(\"" . filename . ".Rmd\", knitrBootstrap::bootstrap_document)"
  if g:vimrplugin_openhtml
    let rcmd = rcmd . '; browseURL("' . filename . '.html")'
  endif
  call g:SendCmdToR(rcmd)
endfunction

"bind RMakeHTML_2 to leader kk
nnoremap <silent> <Leader>kk :call RMakeHTML_2()<CR>

Makefile

You can use the included Makefile to generate html reports from Rmd files from the command line. If you have a file file.Rmd and you want to create file.html use

#standard
make file.html

#with bootstrap style chooser
make THEME_CHOOSER=TRUE file.html

#with code style chooser
make HIGHLIGHT_CHOOSER=TRUE file.html

#with both
make HIGHLIGHT_CHOOSER=TRUE THEME_CHOOSER=TRUE file.html

#standalone
make file_inline.html

Options

Knitr bootstrap extends knitr with a number of additional options. See Knitr Options for more about how to set the two different types of options.

Package Options

  • bootstrap.title - (NULL) Set the title for the html document
  • bootstrap.theme.chooser - (FALSE) - Add a bootstrap style chooser to the page.
  • bootstrap.highlight.chooser - (FALSE) - Add a code style chooser to the page.
  • bootstrap.theme - (Default) - Set the default bootstrap style.
  • bootstrap.highlight - (HighlightJS) - Set the default code style.
  • bootstrap.menu - (TRUE) - Whether to include the bottom navbar.
  • custom.header - (NULL) - External HTML header contents to include in header block.
  • clean_supporting - (TRUE) - Clean the intermediate supporting documents. (this is only an option for the bootstap_document function)

Chunk Options

  • bootstrap.thumbnail - (TRUE) - Thumbnail and lightbox images.
  • bootstrap.thumbnail.size - ('col-md-6') - Thumbnail size in bootstrap columns. (see Bootstrap Grid System)
  • bootstrap.panel - (FALSE) - Use panels rather than buttons to toggle blocks.
  • bootstrap.show.code - (TRUE) - Code from this chunk starts as shown.
  • bootstrap.show.output - (TRUE) - Output from this chunk starts as shown.
  • bootstrap.show.message - (TRUE) - message from this chunk starts as shown.
  • bootstrap.show.warning - (TRUE) - warning from this chunk starts as shown.
  • bootstrap.show.error - (TRUE) - error from this chunk starts as shown.
  • bootstrap.class - ('row') - Bootstrap class to apply to the div containing the chunk.

Bootstrap Themes

Highlight Themes

Highlight Live Test

  • HighlightJs
  • Dark
  • Far
  • Idea
  • Sunburst
  • Zenburn
  • Visual Studio
  • Ascetic
  • Magula
  • Github
  • Google Code
  • Brown Paper
  • School Book
  • IR Black
  • Solarized - Dark
  • Solarized - Light
  • Arta
  • Monokai
  • Xcode
  • Pojoaque
  • Rainbow
  • Tomorrow
  • Tomorrow Night
  • Tomorrow Night Bright
  • Tomorrow Night Blue
  • Tomorrow Night Eighties

knitrbootstrap's People

Contributors

jimhester avatar khughitt avatar lcolladotor avatar mik4unix avatar yihui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

knitrbootstrap's Issues

`code_style` only works if `chooser` includes `code`

This doesn't work (the output has default code style despite code_style parameter):

knit_bootstrap('./test.Rmd', code_style='Solarized - Dark')

But this does work:

knit_bootstrap('./test.Rmd', code_style='Solarized - Dark', chooser='code')

So apparently the code_style param only takes effect if the code chooser is present. Seems like a bug to me.

Understanding time spent in pandoc step

Hello,

I'm not sure whether to ask this here or at https://github.com/rstudio/rmarkdown. Anyhow, using rmarkdown and knitrBootstrap I generated an HTML file that includes among other things around 110 plots and a datatable output with 2000 rows made with rCharts.

When generating the report, I basically take the Sys.time() just before creating the report, and then again at the end of the Rmd file, to then calculate the difference. This is how I know how much time was spent running the R code inside the report. Now, because I was running this in a cluster, I get an email with information as shown below:

 Start Time       = 04/23/2014 17:05:33
 End Time         = 04/23/2014 22:02:23
 User Time        = 01:11:27
 System Time      = 00:02:30
 Wallclock Time   = 04:56:50
 CPU              = 01:13:58

From this, I can see that loading the data needed for the report, running the code in the Rmd file, and then converting the md output to HTML with pandoc took nearly 5 hours. Yet, the time running the R code took ~52 min and was completed at 2014-04-23 18:20:11 EDT. So, around 23 minutes were spent loading the data and 3 hrs 40 min on the pandoc step.

I was surprised by this as I would normally expect running the R code to be the slowest part. Now, the resulting HTML output is ~46 mb big. I know that the recipient hard disk on the cluster network was under heavy I/O load due to someone's else jobs. So maybe that increased the pandoc time, but still, not ~4x vs the R code step.

Any clues? Is there anything I could do to speed things up? Well, maybe generating less plots but that would against the purpose of the report I'm generating.

I'll try re-running it later when the I/O load is lower on the disk, just to rule this out.

Thanks!

Details

The plots were generated using the dev="CairoPNG" knitr option.

There is the R session info:

## R version 3.1.0 Patched (2014-04-23 r65467)
## Platform: x86_64-unknown-linux-gnu (64-bit)
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] grid      parallel  methods   stats     graphics  grDevices utils    
## [8] datasets  base     
## 
## other attached packages:
##  [1] rCharts_0.4.2                           
##  [2] derfinder_0.0.57                        
##  [3] mgcv_1.7-29                             
##  [4] nlme_3.1-117                            
##  [5] RColorBrewer_1.0-5                      
##  [6] xtable_1.7-3                            
##  [7] data.table_1.9.2                        
##  [8] gridExtra_0.9.1                         
##  [9] ggplot2_0.9.3.1                         
## [10] TxDb.Hsapiens.UCSC.hg19.knownGene_2.14.0
## [11] GenomicFeatures_1.16.0                  
## [12] AnnotationDbi_1.26.0                    
## [13] Biobase_2.24.0                          
## [14] GenomicRanges_1.16.2                    
## [15] GenomeInfoDb_1.0.2                      
## [16] IRanges_1.22.3                          
## [17] BiocGenerics_0.10.0                     
## [18] biovizBase_1.12.0                       
## [19] derfinderReport_0.0.16                  
## 
## loaded via a namespace (and not attached):
##  [1] BatchJobs_1.2            BBmisc_1.5              
##  [3] bibtex_0.3-6             BiocParallel_0.6.0      
##  [5] biomaRt_2.20.0           Biostrings_2.32.0       
##  [7] bitops_1.0-6             brew_1.0-6              
##  [9] BSgenome_1.32.0          bumphunter_1.4.0        
## [11] Cairo_1.5-5              cluster_1.15.2          
## [13] codetools_0.2-8          colorspace_1.2-4        
## [15] DBI_0.2-7                dichromat_2.0-0         
## [17] digest_0.6.4             doRNG_1.6               
## [19] evaluate_0.5.3           fail_1.2                
## [21] foreach_1.4.2            formatR_0.10            
## [23] Formula_1.1-1            GenomicAlignments_1.0.0 
## [25] ggbio_1.12.0             gtable_0.1.2            
## [27] Hmisc_3.14-4             httr_0.3                
## [29] iterators_1.0.7          knitcitations_0.5-0     
## [31] knitr_1.5.31             knitrBootstrap_1.0.0    
## [33] labeling_0.2             lattice_0.20-29         
## [35] latticeExtra_0.6-26      locfit_1.5-9.1          
## [37] markdown_0.6.5           MASS_7.3-31             
## [39] Matrix_1.1-3             matrixStats_0.8.14      
## [41] munsell_0.4.2            pkgmaker_0.20           
## [43] plyr_1.8.1               proto_0.3-10            
## [45] qvalue_1.38.0            Rcpp_0.11.1             
## [47] RCurl_1.95-4.1           registry_0.2            
## [49] reshape2_1.2.2           RJSONIO_1.0-3           
## [51] rmarkdown_0.1.84         R.methodsS3_1.6.1       
## [53] rngtools_1.2.4           Rsamtools_1.16.0        
## [55] RSQLite_0.11.4           rtracklayer_1.24.0      
## [57] scales_0.2.4             sendmailR_1.1-2         
## [59] splines_3.1.0            stats4_3.1.0            
## [61] stringr_0.6.2            survival_2.37-7         
## [63] tcltk_3.1.0              tools_3.1.0             
## [65] VariantAnnotation_1.10.0 whisker_0.3-2           
## [67] XML_3.98-1.1             XVector_0.4.0           
## [69] yaml_2.1.11              zlibbioc_1.10.0

Pandoc info

$ pandoc --version
pandoc 1.12.3.1
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: /home/bst/student/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

The actual pandoc call

/jhpce/shared/jhpce/core/JHPCE_tools/1.0/bin/pandoc basicExploration.utf8.md --to html --from markdown-hard_line_breaks+superscript+tex_math_dollars+raw_html+markdown_in_html_blocks-implicit_
figures --output basicExploration.html --filter /jhpce/shared/jhpce/core/JHPCE_tools/1.0/bin/pandoc-citeproc -H /scratch/temp/660049.1.shared.q/RtmpgjQsCg/knitr_bootstrap_full.html

Call to derfinderReport::generateReport(). This is a package I'm making at https://github.com/lcolladotor/derfinderReport

## generateReport(prefix = "run2-v0.0.46", browse = FALSE, makeBestClusters = FALSE, 
##     nBestClusters = 20, fullCov = fullCov, device = "CairoPNG")

Support manually embedded figures

I recently came across your knitrBootstrap package, which is really fantastic and the reason why I know switched from Rnw (LaTex) to Rmd mainly.

I sometimes want to include a more polished figure, than the one generated by R. With Rnw I would usually do:

<<someFigure, …more_params…, show="hide">>=
code to generate the figure
@

\begin{figure}
\includegraphics{polished_plot}

\end(figure}

Math markup

I noticed certain texmath entries in .Rmd docs are being marked up differently in knitrBootstrap than in RStudio's HTML parser (correct term?):

knitrBootstrap: .... (lots of these)
Rstudio's HTML: (.....) (the usual mathjax notation)

I'm getting better results with the second syntax; a table filled with equations renders properly with RStudio's knit button, but not with knitrBootstrap (specified with YAML block). Would it be possible to use the same markup in knitrBootstrap as in RStudio's HTML method for math?

Remove jquery dependency

JQuery is pretty heavyweight, do we really need it, especially if we go forward with #32 and output correctly formatted HTML for bootstrap directly.

Set-up Confusion with the New Github Version

Hi Jim,
I was able to install the updated package via github after installing rmarkdown and a few other dependencies needed to run the vignettes. Unfortunately, now my knit fails to produce the html file. I am using the newest version of RStudio, so I had previously set my defaults via global options:

options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
library(knitrBootstrap)
knit_bootstrap_md(input=inputFile, output=outputFile, code_style="Visual Basic", chooser=c("boot", "code"), show_code=TRUE)
}
)

With the new package, I now get an error:
Error in knit_bootstrap_md(input = inputFile, output = outputFile, code_style = "Visual Basic", :
unused arguments (code_style = "Visual Basic", chooser = c("boot", "code"), show_code = TRUE)

Taking out these arguments allows it to run:
options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
library(knitrBootstrap)
knit_bootstrap_md(input=inputFile, output=outputFile)
}
)

but results in no left margin and no knitrBootstrap additions (similar to a badly formatted typical knitr output).

I then tried the YAML front matter from the README:


output: knitrBootstrap::bootstrap_document:
title: "Test file"
theme: amelia
highlight: sunburst
theme.chooser: TRUE
highlight.chooser: TRUE


But this just puts these words as the first line of my html. I tried with a full range of options(rstudio.markdownToHTML = ...) from the NULL default to those included above.

What am I missing?? I haven't used YAML front matter before, so perhaps I am missing something in the set-up?

I then tried
library(knitrBootstrap)
library(rmarkdown)
render('SpatialProcessingR.Rmd', knitrBootstrap::bootstrap_document)

And after updating my pandoc from 1.12.1 to the 1.12.3 required, I got this error:
Error: Unrecognized output format specified

Thanks again,
Jill

Add option to output to PDF?

I'm not sure how straight-forward this would be, but would it be possible to add an option to output to PDF? This seems like something Pandoc should be able to handle with a little bit of tweaking.

My ultimate goal is to have a documented knitted once, and converted to both PDF and HTML; this way I can easily archive output at various stages as PDF.

show_code=FALSE has different behavior in knit_boostrap() vs knit_bootstrap_md() [broken here]

Hello,

I am getting different output when I use knit_bootstrap() and knit_bootstrap_md() with show_code=FALSE.

The way I have things setup, I use knit_boostrap() when working in Textmate2. Basically, I have a shortcut that runs a short bash script that opens R and runs:

library(knitrBootstrap); knit_bootstrap('$FILE', code_style='Brown Paper', chooser=c('boot', 'code'), show_code=FALSE)

As for RStudio, following the setup instructions, this is my .Rprofile https://gist.github.com/lcolladotor/6393166 I use RStudio when I want to submit the html to RPubs. For example, this is the output http://rpubs.com/lcollado/7904

The problem is that show_code=FALSE is not working, and well, you can't toggle code blocks anymore. This is how the output looks like when using knit_boostrap() directly http://biostat.jhsph.edu/~lcollado/misc/outliers-notInteractive.html

Here is the original Rmd file https://gist.github.com/lcolladotor/6370224

In the end, I think that this is related to the fact that knit_boostrap() uses knitr::knit() Or maybe it's also related to knitr::render_html()

Cheers,
Leo

PS, what are the options for the 'graphics' parameter? I can see that it's used in get_style() but I couldn't figure out the options from looking at the code.

Tasks

  • Unit test R code
  • Unit test jquery code (use qunit?)
  • Make into R package, wrapping function for knit2html wrapper?
    • turn on/off optional features?
  • convert svg imgs to object to fix (rstudio/markdown#18) in webkit browsers
  • Navbar improvements
    • Checkboxes instead of links
    • Dropdown for toggling code by type
  • Add back MathTex support in html header
  • Embed external script sourcecode in code blocks as links
  • figure out how create html if https://github.com/rstudio/markdown/pull/23 is not accepted
  • write installation instructions for Rstudio and vimrc
  • Debug errors in syntax highlighting
  • Add more examples
    • Showing nested TOC
    • Multiple plots per code block
  • Option to hide all code blocks completely
  • Use some lightbox plugin for the images maybe???
  • Embed javascript and css so files are completely standalone?
  • only put last author block as footer with child documents
  • change map example to use less space, the html files are too big
  • See if I can fix the table of contents when the window size is skinny, might not be able to do so.

DESCRIPTION URL & BugReports link 404s

The links in DESCRIPTION all point to [https://github.com/hesterj] which 404s on GitHub. It appears the base URL should be [https://github.com/jimhester].

HTML output broken when served over HTTPS

Currently all of the javascript and CSS include URLs use http:// schemes, which means that if you try to serve your knit_bootstrap-generated content over HTTPS, the page is broken because most browsers block the inclusion of HTTP content by an HTTPS page (or at least show a scary warning).

Most of the include URLs can have the http:// scheme replaced by https:// successfully (yandex, netdna, etc.), with the exception of:

  • http://gregfranko.com (tocify)
  • http://dimsemenov.com (magnific)

These two servers do not have HTTPS versions available. Perhaps there are HTTPS mirrors available.

Suggestions for customization, feature improvement

  • Substitute “+/- Output” with some other text
  • Substitute “ +/- R Code” with some other text
  • Align a chart/table left or right; insert a text block right or left if needed.
  • Hide all Menu items below
  • Drop the first column

UTF-8 Encoding Problem (Tíldes)

Hi!

I write you because I've had problems with the encoding on the website in which I have been working. When I write words in Spanish, that have accent, when I seeing the accent simbole html document is changed by other symbols. I attached an example of what I'm discussing them. I would like you to help me solve this problem.

Thank you for your attention. regards

problema_knitr_bootstrap
knitr_bootstrap
knitr

encoding issue

Thanks for fantastic package.

Under some environment, knit_bootstrap doesn't work due to the encoding issue.
This is because markdown::markdownToHTML couldn't handle encoding.
I have written a patch, and I hope the patch will be merged.
rstudio/markdown#50

After this patch, it is very easy to make knitrBootstrap to work with non-UTF8 MBCS.
I can write a patch and send PR.

Another problem is read_char. read_char may have a trouble under non-UTF8 MB locale (as shown in the help file). So is there any reason you uses read_char instead of readLines?

rCharts and knitrBootstrap interaction via results="asis" breaks menu and code toggling

Hello,

I am using rCharts to display a dynamic table (DataTable via the dTable function) and knitrBoostrap to get the nice HTML layout. While the rCharts code is working now (see ramnathv/rCharts#227) the HTML is showing as intended.

Basically, the output of knit_boostrap("outliers.Rmd", code_style='Brown Paper', chooser=c('boot', 'code'), show_code=FALSE) is this http://biostat.jhsph.edu/~lcollado/misc/outliers.html The menu is not showing and the R code is showing even though it should be hidden. The code toggling still works except for the code chunks that build the rCharts tables.

I think that this might be related to #15 as the code chunks that call rCharts have the results="asis" option.

The original Rmd file is available here https://gist.github.com/lcolladotor/6393393

Thank you,
Leo

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

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.

Setting up title for the whole document in RStudio

I'm able to use bootstrap knitr in Rstudio after editing my .Rprofile file properly, however I can't seem to be able to set up the document title. How do I do that? I'm able to place headers and everything else just fine. In the .Rprofile, I have have:

options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
library(knitrBootstrap)
knit_bootstrap_md(input=inputFile, output=outputFile, chooser=c("boot", "code"), show_code=FALSE, show_output=FALSE)
}
)

Here's what I have for the Rmarkdown file:


---
output:
  knitrBootstrap::bootstrap_document:
    title: "Test file"
    theme: amelia
    highlight: sunburst
    theme.chooser: TRUE
    highlight.chooser: TRUE

---
A level-one header
=====

$$y=1$$

This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages     (click the **Help** toolbar button for more details on using R Markdown).

When you click the **Knit HTML** button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r, bootstrap.panel = FALSE }
library(knitr)
render_html()
summary(cars)
```

You can also embed plots, for example:

```{r fig.width=7, fig.height=6}
plot(cars)
```   

Error in knit - Unused Arguments on Basic Example

I tried to run a basic example and got an error that there are unused arguments.

The file ex1.Rmd is simply the basic RMD file that opens in RStudio.

Here is my full code.

> install.packages("knitrBootstrap")
package ‘knitrBootstrap’ successfully unpacked and MD5 sums checked
> setwd("~/Dropbox/Projects/knitr-bootstrap-example")
> list.files()
[1] "ex1.Rmd" "test.Rmd"
> library(knitrBootstrap)
> knit_bootstrap('ex1.Rmd')
Error in knit(input, NULL, text = text, envir = envir, encoding = encoding, : unused argument(s) (quiet = quiet)

Here is my session:

sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitrBootstrap_0.6.5 markdown_0.6.1 knitr_1.1
loaded via a namespace (and not attached):
[1] digest_0.6.3 evaluate_0.4.3 formatR_0.7 stringr_0.6.2 tools_2.15.3

Currently broken, most likely due to changes in `rmarkdown` 0.1.73

Hello,

With the newest version of rmarkdown (0.1.73), knitrBootstrap is broken as shown below.

Using a very simple test.Rmd file (see https://gist.github.com/10429813) produces the following error

> library(knitrBootstrap)
> library(rmarkdown)
> render("test.Rmd", bootstrap_document())


processing file: test.Rmd
  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      |  67%
label: unnamed-chunk-1
  |.................................................................| 100%
  ordinary text without R code


output file: test.knit.md

Error in knitr::knit_meta(class = "rmd_warning", clean = TRUE) :
  unused argument (class = "rmd_warning")
> sessionInfo()
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] rmarkdown_0.1.73     knitrBootstrap_1.0.0 colorout_1.0-2

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
[6] tools_3.1.0

This is most likely due to the recent changes in the rmarkdown package, which I can see is under heavy development. It might be best to double check with the authors (@jjallaire) so hopefully new changes in rmarkdown won't break knitrBootstrap.

Add to CRAN taskview for reproducible research?

I was thinking that it would be nice to have knitrBootstrap listed under the CRAN task view for reproducible research http://cran.r-project.org/web/views/ReproducibleResearch.html.

My guess is that you only have to email the maintainer to get added to the list.

Cheers

Notes

  • [2014-04-10] Apologies if this gets duplicated. I think that it failed to post with GitHub's latency issues today.
  • [2014-04-11] Hm... third attempt. Doesn't seem like it got posted yesterday.

Images removed by javascript when echo=FALSE

Hi,

If I apply knitr_bootstrap on the following file, everything works fine :

# hello markdown
```{r hello-random, echo=TRUE}
plot(rnorm(5))
```

But if I switch to echo=FALSE, then the image is not displayed anymore in the final html file.

I think the reason is that when echo=FALSE, there is no <div class="source"> around code chunk anymore, however the javascript which handles thumbnails requires it to insert the images in the DOM :

$('div.rimage').each(function(){
    var imgs = $(this).children('img');

    var source = $(this).prev('.source');
    source.addClass('media-body');

    $(this).add(source).wrapAll('<div class="media" />');

    //remove div
    $(this).remove();

    //remove images
    imgs.remove();

    //add images before source
    source.before(imgs);

    //add wrapping links to images
    imgs.wrap('<a href="#" class="media-object pull-left mfp-image thumbnail ' + thumbsize + '"></a>');
  });

Thanks a lot for your very useful package !

long TOC which doesn't scroll

One thing you may notice if your browser window is relatively small is that there are some TOC entries that can't be seen unless you make the window bigger (the last one is "Canned Comments check"). Is there a way to fix that? Maybe to make the TOC scrollable, or at least indicate that it has further content?

Example:
http://bioconductor.org/developers/BiocCheck.html#Namespace_Import_Suggestion_Checks

Possible fixes:
http://stackoverflow.com/questions/12850531/absolutely-positioned-element-going-off-screen-when-filled

Add option to preserve intermediate .md file

There is probably already a way to do this but I have not been able to figure one out yet...

Would it be possible to add an option to preserve the intermediate markdown file when generating a HTML?

Allow toggling thumbnailing

Not everyone likes thumbnails, so there should be a way to disable them completely, not just change their size. Also I think I am going to move them back to underneath the blocks, the output seems too fragile as it is.

Use modified output hooks rather than jquery manipulation

Originally this package was just a replacement header that only modified the knitr HTML output without any R code. However since it now includes some R code it would simplify things to remove as much of the DOM manipulation code as possible and just output the HTML in the correct format from knitr in the first place.

HTML tables in new version

I seem to have trouble generating HTML-based table output using xtable. The code looks like the 2d vignette, but the output does not.

Here's the code:

print(xtable(df.impressions),                                                                                                                                                    
      comment=FALSE,                                                                                                                                                             
      type="html",                                                                                                                                                               
      include.rownames=FALSE                                                                                                                                                     
      )  

knitr_table_error

That output isn't rendered as HTML; it shows up inside an R Output box. The raw HTML for that chunk looks like this:

<pre style="">
<code class="output r">
<TABLE border=1>

(table stuff)
</TABLE>
</code>
</pre>

Setting the code_style does not seem to be working in knit_bootstrap

So using a user define option for code_style does not appear to be working.
For example I use:

knit_bootstrap('test.Rmd', boot_style='Cerulean', code_style='Zenburn', chooser=c('boot','code'))

but this does not affect the syntax highlighting.

Other than that, it's a nice package.

CRAN release

@kohske @jlehtoma @lcolladotor @khughitt @jjallaire,

At some point in the past you expressed interest through questions or bug
reports about knitrBootstrap (https://github.com/jimhester/knitrBootstrap),
to produce Knitr HTML reports utilizing the Bootstrap HTML framework. I have
recently done a major overhaul and rewrite of the package to generate Bootstrap HTML
tags directly using R rather than using javascript to modify the DOM as was done previously.
In addition the package now uses RStudio's new
rmarkdown package to convert the HTML from
markdown and slightly modified the format of the pages in to make them
more consistent and less buggy.

These changes have made the package both easier for me to maintain as well as
easier to enhance. It should also be simpler to use in RStudio and along with
other output formats. I would appreciate both your feedback on the new format
as well as any bugs or feature regressions you find so I can make changes and
fixes before submitting the updates to CRAN.

Thank you for your (past) interest in my package, and I hope these changes improve
your experience!

Jim Hester

I apologize for this slight abuse of the github issue tracker, I did not have an email address to send this message to you!

Control TOC

Is there a way that we can control how the TOC are rendered and displayed?

Specifically, I prefer the tocify-style for the TOC and would like to disable the meny functionality (which is cool, but distracting at times).

How to properly cite?

Hello,

I'm writing a short application note for https://github.com/lcolladotor/derfinderReport and want to cite knitrBootstrap. I used the information from citation('knitrBootstrap') but was wondering if that is indeed how you would like knitrBootstrap to be cited.

Using that information, this would be the citation.

Hester,J. (2014), knitrBootstrap: Knitr Bootstrap framework, R package version
1.0.0, github.com/jimhester/knitrBootstrap.

Thanks

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

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

Code doesn't highltight

This probably isn't a real issue (just me being ignorant), but for some reason, I can't get proper code highlighting using the RStudio option:

options(rstudio.markdownToHTML =
  function(inputFile, outputFile) {
    require(knitrBootstrap)
    knit_bootstrap_md(input=inputFile, output=outputFile)
  }
)

I've also tried changing the default code_style option:

options(rstudio.markdownToHTML =
  function(inputFile, outputFile) {
    require(knitrBootstrap)
    knit_bootstrap_md(input=inputFile, output=outputFile, code_style='tomorrow')
  }
)

Not sure how I can provide a reproducible example, but here is what I'm working on. Also, I'm using RStudio version 0.98.313 and here is my sessionInfo:

R version 3.0.1 (2013-05-16)
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] knitrBootstrap_0.8.0 markdown_0.6.3       knitr_1.5            dlm_1.1-3            XML2R_0.1           
[6] roxygen2_2.2.2       digest_0.6.3         devtools_1.3        

loaded via a namespace (and not attached):
 [1] brew_1.0-6     evaluate_0.5   formatR_0.9    httr_0.2       memoise_0.1    parallel_3.0.1 plyr_1.8       RCurl_1.95-4.1
 [9] stringr_0.6.2  tools_3.0.1    whisker_0.3-2  XML_3.95-0.2  

incompatibility with pandoc citations

With the minimal .Rmd file below, the div in which the references are placed floats off below the final knitrBookstrap credit at the bottom. (Note that to reproduce the problem, you have to actually have @kellogg_logic_2004 in the .bib file for the reference to be produced.)


---
output:
  knitrBootstrap::bootstrap_document

bibliography: "mybib.bib"

---

# a heading
# Bibliography

[@kellogg_logic_2004]

The bottom of the resulting html file looks like this:

<div class="references">
<p>Kellogg, W. K. 2004. “Logic Model Development Guide.”</p>
</div>
</body>
</html>

Deactivate meny?

Hi,

Thank you very much for this package. Is there any way to deactivate meny ? The three dimensional menu is pretty, but a bit cumbersome...

Again, thank you very much.

Best,
David

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.