Graphics device for inclusion of plots in FastRWeb results.

Description

WebPlot opens a new graphics device (currently based on Cairo) and returns an object that can be used as a result of FastRWeb functions or in web output.

Usage

1
WebPlot(width = 640, height = 480, type = "png", ...)

Arguments

width

width of the resulting plot (normally in pixels)

height

height of the resulting plot (normally in pixels)

type

type of the output

...

furhter arguments to be passed to Cairo

Details

WebPlot generates a temporary file name that is accessible using the "tmpfile" command of WebResult and opens a new Cairo device with the specified parameteres. It returns a WebPlot object that can be either retured directly from the run() function (and thus resulting in one image) or used with the out() function to reference the image in an HTML page (see examples below).

Note that as.WebResult coercion is used to finalize the result when returned directly and it will close the device, so dev.off() is optional and not needed in that case. Also WebPlot reserves the right to close any or all other active WebPlot devices - this ensures that dev.off() may not be neeed at all even when using multiple WebPlots.

Value

WebPlot object.

The structure of the WebPlot class is considered internal and should not be created directly. Current attributes include file (filename), type (output type), mime (MIME type), width, height.

Author(s)

Simon Urbanek

See Also

WebResult

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
## example 1: single image
## if saved as "plot.png.R"
## it can be served as http://server/cgi-bin/R/plot.png
run <- function(n = 100, ...) {
  n <- as.integer(n)
  # create the WebPlto device
  p <- WebPlot(800, 600)
  # plot ...
  plot(rnorm(n), rnorm(n), pch=19, col="#ff000080")
  # return the WebPlot result
  p
}

## example 2: page containing multiple images
## if saved as "plotex.html.R"
## it can be served as http://server/cgi-bin/R/plotex.html
run <- function(...) {
  out("<h2>Simple example<h2>")
  data(iris) ## ideally, you'll use data from the Rserve session
  attach(iris)
  p <- WebPlot(600, 600)
  plot(Sepal.Length, Petal.Length, pch=19, col=Species)
  out(p)
  p <- WebPlot(350, 600)
  barplot(table(Species), col=seq.int(levels(Species)))
  out(p)
  done()
}