### Department of Bioinformatics and Computational Biology

Home > Public Software > NG-CHM R > Embedded NGCHM into RMarkdown

## Embed NGCHM into HTML with Knitr

This vignette demonstrates how to construct and embed a simple NG-CHM into R Markdown, then generates a report with knitr. The following sections are below:

### Creating an R Markdown file

Creating report with R Markdown starts with a .Rmd file that contains a combination of formatted text and R code chunks. The .Rmd file is fed to knitr, which executes all the R code chunks and create .md document which includes the R code and its output. The markdown file generated by knitr is then processed by pandoc which is used for creating a finished webpage.


---
output:
html_document:
toc: true
toc_float: true
toc_collapsed: false
toc_depth: 2
number_sections: true
theme:  cerulean
smooth_scroll: true
params:
title:  Embedded NGCHM
author: MD Anderson Cancer Center, Houston, TX
plot: NA
---


{r setup, include=FALSE}
knitr::opts_chunk\$set(echo = FALSE,fig.align="center")

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.


### Creating a NG-CHM

This vignette uses an additional package of demo data, NGCHMDemoData , which can be installed from GitHub with remotes :

The NG-CHM is exported as a stand-alone HTML file with the chmExportToHTML() funciton. The first argument is the NG-CHM created above with chmNew command. The second argument is the desired filename, and the third is a boolean dictating if any existing file of that name should be overwritten.

{r, echo = FALSE,warning=FALSE, fig.width=20, fig.height=16,fig.align="center", message=FALSE, warning=FALSE}

remotes::install_github('MD-Anderson-Bioinformatics/NGCHMDemoData', ref='main')
library(NGCHMDemoData)
library(NGCHM)
library(NGCHMSupportFiles)
hm <- chmNew('tcga-gbm', TCGA.GBM.ExpressionData)
dataPath=paste(getwd(),'/tcga-gbm.html',sep="")
chmExportToHTML(hm,dataPath,overwrite=TRUE)



### Embedding to R Markdown

htmltools is an R package designed to generate HTML tags from R, we will use htmltools to include generated NGCHM html file as an iframe.

{r}
library("htmltools")
htmltools::includeHTML(dataPath)



RStudio includes a Kint button that enables the readering of .Rmd and preview it with a single click. From R Studio, just click on Knit button to generate HTML file.