Render rCharts in slides by Slidify

I recently experimented with slidify and rCharts . The tutorials for creating simple diagrams when using slidify are explanatory, but I could not find such a tutorial regarding rCharts.

For example, I know that the following generates an interactive plot

 data(mtcars) r1<- rPlot(mpg ~ wt | am + vs, data=mtcars, type="point") data(iris) hair_eye = as.data.frame(HairEyeColor) rPlot(Freq ~ Hair | Eye,color = 'Eye', data = hair_eye, type = 'bar') 

However, I do not know how to include the result in my slides using slidify .

EDIT - after a helpful comment

I tried the following after seeing it on Ramnath git :

 --- title : Practice subtitle : makes perfect author : Noob job : framework : io2012 # {io2012, html5slides, shower, dzslides, ...} highlighter : highlight.js # {highlight.js, prettify, highlight} hitheme : tomorrow # widgets : [nvd3] # {mathjax, quiz, bootstrap} mode : selfcontained # {standalone, draft} --- ```{r setup, message = F, echo = F} require(rCharts) options(RCHART_WIDTH = 800, RCHART_HEIGHT = 500) knitr::opts_chunk$set(comment = NA, results = 'asis', tidy = F, message = F) ``` ## NVD3 Scatterplot ```{r echo = F} data(mtcars) n1 <- nPlot(mpg ~ wt, group = 'gear', data = mtcars, type = 'scatterChart') n1$print('chart1') ``` 

But ended up with this error:

 Error in file(con, "r") : cannot open the connection In addition: Warning message: In file(con, "r") : cannot open file 'libraries/widgets/nvd3/nvd3.html': No such file or directory 

After which I decided to copy the nvd3 folder from Ramnath widgets directly to mine, hoping that this would solve the issue. However, this madly showed the Ramnath git page, as well as my slides in the background!

What to do? I would really appreciate any recommendations / recommendations / recommendations on how to accomplish this task. And hopefully this question will help other newbies like me to use the wonderful rCharts.

Note. I use the standard editor for R, not R-studio. I feel the first is less cluttered.

+6
source share
1 answer

All of the instructions below assume that you have the dev branch of installed packages (slidify, slidifyLibraries and rCharts). You can accomplish this with install_github .

 pkgs <- c("slidify", "slidifyLibraries", "rCharts") devtools::install_github(pkgs, "ramnathv", ref = "dev") 

There are two ways to include rCharts in your slidify document, and the bottom panel below illustrates both methods. If you print the plot in a block of code, as you would in the R console, slidify automatically detects that you are launching it in a knitr session, and as a result, save the resulting html in an iframe and paste it into the deck. Alternatively, you can specify an inline diagram, in which case you should use n1$show("inline") and also include ext_widgets: {rCharts: libraries/nvd3} in your first YAML question.

The iframe method is the standard and recommended method for preventing conflicts between different javascript and css files. The built-in method works well for several rCharts libraries, but be sure to check before using.

 --- title : rCharts Integration ext_widgets : {rCharts: libraries/nvd3} mode: selfcontained --- ## NVD3 Plot Inline ```{r nvd3plot, results = 'asis', comment = NA, message = F, echo = F} require(rCharts) n1 <- nPlot(mpg ~ wt, data = mtcars, type = 'scatterChart') n1$show('inline') ``` --- ## NVD3 Plot Iframe ```{r nvd3plot2, results = 'asis', comment = NA, message = F, echo = F} require(rCharts) n1 <- nPlot(mpg ~ wt, data = mtcars, type = 'scatterChart') n1 ``` 
+8
source

Source: https://habr.com/ru/post/952316/


All Articles