I am programming an extensive data document that relies partly on some shiny features.
I would like to implement rCharts and I found out how to do it with a clean RMarkdown document.
I am running into trouble as soon as I want to turn on the Shiny features so that the rest of the document works as supposed to.
The code below works as it should
---
title: "Paper 4"
author: "Kasper Christensen"
date: "Monday, June 01, 2015"
output: html_document
runtime: html
---
```{r, echo=FALSE, results='asis', comment=NA, warning=FALSE, message=FALSE}
library(ggvis)
library(rCharts)
library(plotly)
library(stringr)
library(reshape2)
library(reshape)
require(rCharts)
.libPaths("C:/R/R-3.1.3/library/")
# data
ds <- read.csv("data/misc/FullDS_2015-01-13.csv")
ds <- subset(ds, X_golden == "false")
ds <- ds[c(4,8)]
ds <- as.data.frame(table(ds))
# plot
m2 <- nPlot(Freq ~ TARGET, group = "GROUP", data = ds, type = "multiBarChart")
m2$print('iframesrc', cdn =TRUE, include_assets=TRUE)
```
This does not work
---
title: "Paper 4"
author: "Kasper Christensen"
date: "Monday, June 01, 2015"
output: html_document
runtime: shiny
---
```{r, echo=FALSE, results='asis', comment=NA, warning=FALSE, message=FALSE}
library(ggvis)
library(rCharts)
library(plotly)
library(stringr)
library(reshape2)
library(reshape)
require(rCharts)
.libPaths("C:/R/R-3.1.3/library/")
# data
ds <- read.csv("data/misc/FullDS_2015-01-13.csv")
ds <- subset(ds, X_golden == "false")
ds <- ds[c(4,8)]
ds <- as.data.frame(table(ds))
# plot
m2 <- nPlot(Freq ~ TARGET, group = "GROUP", data = ds, type = "multiBarChart")
m2$print('iframesrc', cdn =TRUE, include_assets=TRUE)
```
So my question is how to embed an rChart into a shiny Rmarkdown document?
Here is my solution even thought I am aware it is not the best.
First step:
Create an external
html
file that contains the rChart you want to include. Here is the code:Where the
save()
function allows us to save then1
rChart object to an external html file, obviously made up of pure HTML code. This example is from here.I saved this file as
grap.html
in the same directory where we shall create the html to include in.Second step:
create an RMarkdown file. I used the one of example provide by Rstudio. He point here is the option(s)
includes:
.It allows to include a pure HTML at the end of the body of your HTML. If you want to add at the bottom I think you have to specify
before_body: grap.html
It is not perfect but may be a start and trigger the ideas of other users. You can find other informations: http://rmarkdown.rstudio.com/html_document_format.html#html-fragments