Generating plots in R is supported through Storage file uploads. To upload a plot to Storage,
save the file in the output directory for files (
out/files/). Each file in that directory will be automatically saved into Storage File Uploads.
To make file handling a bit easier, it is possible to write a manifest, which describes the file. This can be used to set file tags
and other file upload options. To write the manifest, use the
app$writeFileManifest function with the following signature:
Remember to use the
out/files/ directory for plots. And note that the
rDocker tag will be automatically added to all files with manifests.
In the following examples, use the sample graph-source.csv data file. Create a new bucket in Storage and upload the table to it.
Create a new R transformation, and add the graph-source table in the input mapping. There is no output mapping.
Then use the following R script in the transformation and run it.
Once the transformation finishes, a file will be added to File uploads:
lm.plot function produces multiple plots, the above example plots all four graphs to a
single image using a 2x2 grid.
Use the following script the same way as in Example 1. The only difference is that this script produces multiple files.
If a plot function produces multiple graphs, like the
lm.plot in the above example, use
%d in the file name in order to generate multiple files.
A manifest is written for each file individually.
If you want to use the ggplot package, use a different function for saving a file in your script. The rest remains the same as in the previous examples.
Do not forget to list
ggplot2 in the package section of the transformation.