By Sherry Lamonica-Oracle on Oct 17, 2013
Oracle R Enterprise graphics are returned as raster, or bitmap graphics. Raster images consist of tiny squares of color information referred to as pixels that form points of color to create a complete image. Plots that contain raster images render quickly in R and create small, high-quality exported image files in a wide variety of formats.
However, it is a known issue that the rendering of raster images can be problematic when creating graphics using a Remote Desktop connection. Raster images do not display in the windows device using Remote Desktop under the default settings. This happens because Remote Desktop restricts the number of colors when connecting to a Windows machine to 16 bits per pixel, and interpolating raster graphics requires many colors, at least 32 bits per pixel..
For example, this simple embedded R image plot will be returned in a raster-based format using a standalone Windows machine:
R> ore.connect(user="rquser", sid="orcl", host="localhost", password="rquser", all=TRUE)
R> ore.doEval(function() image(volcano, col=terrain.colors(30)))
Here, we first load the ORE packages and connect to the database instance using database login credentials. The ore.doEval function executes the R code within the database embedded R engine and returns the image back to the client R session.
Over a Remote Desktop
connection under the default settings, this graph will appear blank
due to the restricted number of colors. Users who encounter this
issue have two options to display ORE graphics over Remote Desktop:
either raise Remote Desktop's Color Depth or direct the plot output
to an alternate device.
Option #1: Raise Remote Desktop Color Depth setting
In a Remote Desktop session, all environment variables, including display variables determining Color Depth, are determined by the RCP-Tcp connection settings. For example, users can reduce the Color Depth when connecting over a slow connection. The different settings are 15 bits, 16 bits, 24 bits, or 32 bits per pixel. To raise the Remote Desktop color depth:
On the Windows server, launch Remote Desktop Session Host Configuration from the Accessories menu.
Under Connections, right click on RDP-Tcp and select Properties.
On the Client Settings tab either uncheck LimitMaximum Color Depth or set it to 32 bits per pixel.
Click Apply, then OK, log out of the remote session and reconnect.
After reconnecting, the Color Depth on the Display tab will be set to 32 bits per pixel. Raster graphics will now display as expected. For ORE users, the increased color depth results in slightly reduced performance during plot creation, but the graph will be created instead of displaying an empty plot.
Option #2: Direct plot output to alternate device
Plotting to a non-windows device is a good option if it's not possible to increase Remote Desktop Color Depth, or if performance is degraded when creating the graph. Several device drivers are available for off-screen graphics in R, such as postscript, pdf, and png. On-screen devices include windows, X11 and Cairo.
Here we output to the Cairo device to render an on-screen raster graphic. The grid.raster function in the grid package is analogous to other grid graphical primitives - it draws a raster image within the current plot's grid.
# use Cairo device for plotting during the session
R> library(Cairo) # load Cairo, grid and png libraries
R> res <- ore.doEval(function()image(volcano,col=terrain.colors(30))) # create embedded R plot
R> img <- ore.pull(res, graphics = TRUE)$img[] # extract image
R> grid.raster(as.raster(readPNG(img)), interpolate = FALSE) # generate raster graph
R> dev.off() # turn off first device
By default, the interpolate argument to grid.raster is TRUE, which means that what is actually drawn by R is a linear interpolation of the pixels in the original image. Setting interpolate to FALSE uses a sample from the pixels in the original image.
A list of graphics devices available in R can be found in the Devices help file from the grDevices package: