svgFromHtml: Extract svg graphic data from an html/webarchive file

Description Usage Arguments Value Author(s) See Also Examples

Description

Extract the svg graphic data contained in an .html file or .webarchive file and store it as an .svg file. Some plotting functions, which are based on htmlwidgets like networkD3, generate a html file that contains JavaScript code for the generation of the graphic (i.e. there is no graphic stored in this html file, but the code to generate the graphic). If this file is opened in a standard web browser, the graphic is rendered and displayed. In some cases, the plot can even be manipulated by the user, before saving it as html or webarchive file that contains all elements (i.e. the plot as svg graphic) of the displayed 'website'. The resulting .svg file extracted with this function can be edited with vector graphic tools like Affinity Designer or Inkscape. Using rsvg::rsvg_pdf the .svg file can be directly converted to pdf, or converted to a .png file using rsvg::rsvg_png.

Usage

1

Arguments

file

character file name, including the file typ specifier (e.g. "myplot.html"). The corresponding .html/.webarchive file must contain the svg graphic.

Value

Returns a boolean indicating the success of the attempt to store a .svg file. Also, writes the .svg file, if possible.

Author(s)

Christoph Schmidt <schmidtchristoph@users.noreply.github.com>

See Also

rsvg_pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# file generated by macOS Safari (format = webarchive)
path1 <- system.file("extdata/alplots2.webarchive", package = "js2graphic")
path2 <- paste(getwd(), "/alplots2.webarchive", sep="")
file.copy(path1, path2)
file  <- "alplots2.webarchive"
b     <- svgFromHtml(file)
print(b)
rsvg::rsvg_png("alplots2.svg", "alplots2.png")
rsvg::rsvg_pdf("alplots2.svg", "alplots2.pdf")

file.remove(c(file, "alplots2.svg", "alplots2.png", "alplots2.pdf"))



# file generated by macOS Safari *without* storing web content
path1 <- system.file("extdata/alplots2_noSvg.html", package = "js2graphic")
path2 <- paste(getwd(), "/alplots2_noSvg.html", sep="")
file.copy(path1, path2)
file  <- "alplots2_noSvg.html"
b     <- svgFromHtml(file)  # no svg content
print(b)
file.remove(file)



# file generated by macOS  Firefox (format = website, complete)
path1 <- system.file("extdata/alplots2_ff.html", package = "js2graphic")
path2 <- paste(getwd(), "/alplots2_ff.html", sep="")
file.copy(path1, path2)
file  <- "alplots2_ff.html"
b     <- svgFromHtml(file)
print(b)
rsvg::rsvg_png("alplots2_ff.svg", "alplots2_ff.png")

file.remove(c(file, "alplots2_ff.svg", "alplots2_ff.png"))

schmidtchristoph/js2graphic documentation built on May 21, 2019, 10:08 a.m.