12

I have an existing R package on CRAN (the rms package) for which I desire to add an html vignette created using R Markdown with RStudio. I see most of what I need in the Writing R Extensions manual and at How to get RStudio to automatically compile R Markdown Vignettes?

What is not obvious is that I want to use plotly functions to create interactive graphics. Self-contained html files using this with RStudio work great but I don't know how to make sure such vignettes work with a CRAN submission, and how to set this up.

Community
  • 1
  • 1
Frank Harrell
  • 1,954
  • 2
  • 18
  • 36
  • 2
    I'd check out [the plotly vignettes](https://github.com/ropensci/plotly/tree/master/vignettes), though they don't build properly for me in RStudio. – alistaire Jul 24 '16 at 17:16

1 Answers1

3

I have tried the following. I created an R markdown document (test.Rmd) in RStudio and put in the following.

## Testing interactive graphics

```{r}
library(highcharter)
library(ggplot2)

data(diamonds, economics_long, mpg, package = "ggplot2")
hchart(mpg, "scatter", x = displ, y = hwy, group = class)
```

Convert this 'test.Rmd' to 'test.md' and finally to 'test.html' by clicking on the Knit HTML button in RStudio OR by running the following script in the console:

library(knitr)
knit("test.Rmd", tangle=F, encoding = "utf-8")
render("test.md",output_format=html_document())

This generates an html file with interactive graphics.

hicharter-plot

Yes. This is not plotly but highcharter is a nice R package that includes several interactive javascript plotting libraries and it's easy to use. It's also better documented than rCharts for example. The package maintainer is also friendly and responsive to queries. Install highcharter package here:

library(devtools)
install_github("jbkunst/highcharter")
mindlessgreen
  • 11,059
  • 16
  • 68
  • 113
  • I tried that nice approach with plotly but the plots did not come out. I wonder what differs with highcharter. – Frank Harrell Jul 31 '16 at 23:48
  • I remember this approach did not work with `rCharts`. There was an option to add assets or something. Can't remember. It was a while back. – mindlessgreen Aug 04 '16 at 14:47