Skip to content

Commit 53cf6e4

Browse files
committed
add link functions back
1 parent 1c754a8 commit 53cf6e4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

R/reports.R

+58
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,64 @@
66
# www.fgcz.ch
77

88

9+
ezLink <- function(link, label = link, target = "", type = "") {
10+
linkTag <- paste0("<a href='", link, "'")
11+
if (target != "") {
12+
linkTag <- paste0(linkTag, " target='", target, "'")
13+
}
14+
if (type != "") {
15+
linkTag <- paste0(linkTag, " type='", type, "'")
16+
}
17+
linkTag <- paste0(linkTag, ">")
18+
paste0(linkTag, label, "</a>")
19+
}
20+
21+
22+
23+
# how to add help text? for each plot separately or not?
24+
##' @title Gets an image link as html
25+
##' @description Gets an image link as html. Also plots and creates the image.
26+
##' @param plotCmd an expression of plot commands.
27+
##' @param file a character specifying the name of the image with a .png suffix.
28+
##' @param name a character specifying the name of the image together with \code{plotType}, if \code{file} is null.
29+
##' @param plotType a character specifying the name of the image together with \code{name}, if \code{file} is null.
30+
##' @param mouseOverText a character specifying the text being displayed when mousing over the image.
31+
##' @param addPdfLink a logical indicating whether to add a link on the image to a pdf version of itself.
32+
##' @param width an integer specifying the width of each plot to create an image from.
33+
##' @param height an integer specifying the height of each plot to create an image from.
34+
##' @param ppi an integer specifying points per inch.
35+
##' @param envir the environment to evaluate \code{plotCmd} in.
36+
##' @template roxygen-template
37+
##' @return Returns a character specifying a link to an image in html.
38+
##' @examples
39+
##' x = 1:10
40+
##' plotCmd = expression({
41+
##' plot(x)
42+
##' text(2,1, "my Text")
43+
##' })
44+
##' ezImageFileLink(plotCmd)
45+
ezImageFileLink <- function(plotCmd, file = NULL, name = "imagePlot", plotType = "plot", mouseOverText = "my mouse over",
46+
addPdfLink = TRUE, width = 480, height = 480, ppi = 72, envir = parent.frame()) {
47+
if (is.null(file)) {
48+
file <- paste0(name, "-", plotType, ".png")
49+
}
50+
png(file, width = width, height = height)
51+
eval(plotCmd, envir = envir)
52+
dev.off()
53+
imgFilePot <- paste0("<span><img src='", file, "' title='", mouseOverText, "'/></span>")
54+
if (addPdfLink) {
55+
pdfName <- sub(".png$", ".pdf", file)
56+
pdf(file = pdfName, width = width / ppi, height = height / ppi)
57+
eval(plotCmd, envir = envir)
58+
dev.off()
59+
imgFilePot <- paste0("<a href='", pdfName, "'>", imgFilePot, "</a>")
60+
}
61+
return(imgFilePot)
62+
}
63+
64+
65+
66+
967
##' @title Wrapper for \code{FlexTable()}
1068
##' @description Wraps \code{FlexTable()} with defaults to remove the cell header and cell borders.
1169
##' @param x a matrix or data.frame to turn into an object of the class FlexTable.

0 commit comments

Comments
 (0)