Ron Talbot Ron Talbot - 2 months ago 14x
R Question

How to generate an md file from a rmarkdown file containing an htmlwidget

I am creating an html file with this rmd

title: "test"
author: "me"
date: '`r Sys.Date()`'
output: html_document

rpivotTable::rpivotTable(data = HairEyeColor
, rows = "Hair"
, vals = "Freq"
, aggregatorName = "Sum"
, rendererName = "Table"
, width="100%"
, height="400px")


rmarkdown::render( input = 'file.RMD' , output_file = 'file.html'
, output_format= html_document( self_contained=TRUE), clean = FALSE
, quiet = FALSE )

the output is ok, but I need the markdown file ( to recreate the html file at a later time (without access to the data)

rmarkdown generates two md files [] and []
but when I render any of these two, the htmlwidget is missing in file.html.

rmarkdown::render( input = '' , output_file = 'file.html'
, output_format= html_document( self_contained=TRUE) )

rmarkdown call to pandoc has an [--include-in-header] parameter pointing to a temp file with the widget dependencies, but I am not finding a way to include it when rendering the md file (i.e. --include-in-header /tmp/Rtmp1M0RpP/rmarkdown-str1a169e14827.html" )

Below I pasted the pandoc call from rmarkdown, but again, executing this command alone produced an html file without the htmlwidget.

/usr/bin/pandoc +RTS -K512m -RTS
--to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash
--output test._0021.html --smart --email-obfuscation none --self-contained --standalone
--section-divs --template /home/bergel/R/x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/h/default.html
--variable 'theme:bootstrap' --include-in-header /tmp/RtmpqpGfD1/rmarkdown-str19b5232f45d7.html
--mathjax --variable 'mathjax-url:'
--no-highlight --variable highlightjs=/home/bergel/R/x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/h/highlight
--variable navigationjs=/home/bergel/R/x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/h/navigation-1.1

I want the html file with the interactive htmlwidget, not a png of the widget. Using the code below I can generate a that can then render an html file but with a png of the widget, NOT an interactive js widget.

rmarkdown::render( input = 'file.RMD' , output_file = ''
, output_format= md_document( ) )

I found that this question is related to this one:
Extract html dependencies for .Rmd file (containing htmlwidgets)


Found the problem. I changed

rmarkdown::render(  input = 'file.RMD' , output_file = ''
                    , output_format=   md_document( ) ) 


rmarkdown::render(  input = 'file.RMD' , output_file = ''  )  

and now file.html is ok.