The reporting functions of the infographiqR package work together to generate HTML files from the R Markdown files known as modal windows. The process of rendering a R Markdown file to HTML is a multi-step process. The initial step is to render all of the R code within the R Markdown file, creating a temporary Markdown file. Once that process has completed though, there is a big step remaining before the html can be created from that Markdown file. Namely, any words in the Markdown file that are designated as glossary terms need to be flagged and given necessary html codes. Once this is done, the html is rendered from the Markdown file, with all glossary terms getting a Javascript “tooltip” in the html.
Here’s the steps in the process of rendering the HTML from R Markdown.
generate_html_4_rmd()
: renders a single R Markdown file.render_all_rmd()
: renders all R Markdown files in “modals” directory using generate_html_4_rmd()
.generate_html_4_rmd()
calls rmd2html()
, which creates a temporary Markdown file in which all of the R code in the R Markdown File has been executed.rmd2html()
opens the temporary Markdown file and then calls glossarize_md()
.glossarize_md()
loads up all of the glossary terms in the google sheet where they are stored and then goes through the Markdown file, line by line. Each combination of glossary term and line of the Markdown file is fed into insert_tooltips()
.insert_tooltips()
inserts tooltip-related tags around that term.glossarize_md()
loads the tooltip Javascript library at the bottom of the file (but only if there is at least one glossary term in the file).generate_html_4_rmd()
then renders the edited Markdown file to html. This function also renders the original R Markdown file to a temporary html file using rmarkdown::render()
, as this is the only way to know what the right Javascript libraries are for any interactive elements in the final html. The entire head section of the second html file rewrites the head section of the first html file.