Learn R Programming

hwriterPlus (version 1.0-3)

hwriteSVG: Write HTML Code to Include an SVG Image

Description

Write code to include an SVG image in an HTML document which should work with most modern browsers.

Usage

hwriteSVG(image.url, page = NULL, width = 500, height = 500, id = "", attributes = "border = '0'", ...)

Arguments

image.url
A character vector or matrix containing the URL or the file path of the SVG image.
page
An optional connection. A character string naming the file to write to or a page object returned by newPage or openPage.
width, height
An HTML length unit (in pixels) specifiying the width (respectively height) at which the image should be rendered. Must be present if browser being used is Internet Explorer. If missing, Firefox will use the default image width(resp. height).
id
Character. A string providing an identifier for the SVG image.
attributes
Attributes of the SVG image. See details.
...
Optional arguments that will be dispatched to the underlying hwrite call.

Value

A character vector containing the output HTML code.

Details

Inserting workable SVG code into an HTML document is difficult because the attributes of the tag required depend on the browser used to view the document. hwriteSVG uses syntax taken from support documentation for the SVG Web project. The example given in the sample helloworld.html is

   


  

Note that recent versions of Firefox should display SVG images without problems, and should not require the specification of height and width. Internet Explorer is far less foregiving and both height and width values must be given or no image will be displayed. Experimentation with appropriate values for the arguments may be necessary.

For attributes which may be included in an tag, see the reference for this tag on the website http://www.w3schools.com.

References

http://www.w3schools.com/tags/tag_object.asp http://codinginparadise.org/projects/svgweb/docs/QuickStart.html

See Also

hwriteImage

Examples

Run this code
examplesDir <- file.path(system.file(package = 'hwriterPlus'),
                         'examples')
catsSVG <- file.path(examplesDir, "cats.svg")
### Raw html produced
hwriteSVG(catsSVG, page = NULL, height = 600, width = 600,
          center = FALSE, br = TRUE)
### Formatted  a little more nicely
svgHTML <- hwriteSVG(catsSVG, page = NULL, height = 600, width = 600,
          center = FALSE, br = TRUE)
unlist(strsplit(svgHTML, "\n"))

Run the code above in your browser using DataLab