Stein
Stein

Reputation: 3277

Save plot to html

I created a plot along the lines of this:

http://www.buildingwidgets.com/blog/2015/7/2/week-26-sunburstr

# devtools::install_github("timelyportfolio/sunburstR")

library(sunburstR)

# read in sample visit-sequences.csv data provided in source
#   https://gist.github.com/kerryrodden/7090426#file-visit-sequences-csv
sequence_data <- read.csv(
  paste0(
    "https://gist.githubusercontent.com/kerryrodden/7090426/"
    ,"raw/ad00fcf422541f19b70af5a8a4c5e1460254e6be/visit-sequences.csv"
  )
  ,header=F
  ,stringsAsFactors = FALSE
)

In Rstudio I can click in the Viewer: "Export > Save as Web Page ..."

Which then saves the plot as interactive html-document. I would like to do this as part of the code. How do I save a plot to html using R-code? There are plenty of examples for PDF/jpg etc., but not html.

Upvotes: 2

Views: 5348

Answers (1)

DSGym
DSGym

Reputation: 2867

Store the sunburst in a variable and use htmltools::save_html to save it.

plot <- sunburst(sequence_data)

htmltools::save_html(plot, file = "C:/Users/User/Desktop/sunburst.html")

Upvotes: 7

Related Questions