RpadHTML: HTML utilities

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Rpad utilities to generate HTML output.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
  HTMLon()
  HTMLoff()
  HtmlTree(tagName, ...)
  H(tagName, ...)
  ## Default S3 method:
HtmlTree(tagName, ..., standaloneTag = FALSE, collapseContents = TRUE)
  Html(x, ...)
  BR()
  HTMLargs(x)
  HTMLtag(tagName, ...)
  HTMLetag(tagName)
  HTMLradio(variableName, commonName = "radio", text = "", ...)
  HTMLcheckbox(name, text = "", ...)
  HTMLselect(name, text, default = 1, size = 1, id = name,
    contenteditablewrapper = TRUE, optionvalue = text, ...)
  HTMLinput(name, value = "", rpadType = "Rvariable", contenteditablewrapper = TRUE, ...)
  HTMLlink(url, text, ...)
  HTMLimg(filename = get("plot.name", envir = .RpadEnv), ...)
  HTMLembed(filename, width = 600, height = 600, ...)
  HfromHTML(x)
  print.condition(x, ...)

Arguments

text

specifies the text to be displayed in the HTML output.

tagName

is a string specifying the HTML nodeName ("H1" or "DIV" for example).

standaloneTag

is a logical that specifies whether the HTML tag is a standalone tag, meaning it has no ending tag (<br/> for example).

collapseContents

is a logical that specifies whether vector tag contents are collapsed (merged).

variableName, commonName

specify attributes of the radio element. commonName specifies the common radio elements that are grouped together (the name attribute of the radio element)–this gets translated into the R variable with the same name. variableName is the string result assigned to commonName when this radio item is selected (the value attribute of the radio element).

name

is the name attribute in HTML that is translated into the R variable with the same name.

value

is the initial value of the input box.

url

is the URL for the <A> element.

contenteditablewrapper

is a logical that specifies whether a wrapper is placed around the output to disable editing. Internet Explorer needs this to make links and input elements active.

default, size, id, optionvalue

specify parameters of a select box. default specifies which of the options is selected initially.

filename, width, height

are parameters of an IMG or EMBED object.

rpadType

is the "rpadType" attribute of an INPUT element. Normal values are either "Rvariable" or "Rstring" but other values of "rpadType" should also be possible.

x

== To define ==

...

arguments are passed on as HTML arguments for the given tag.

Details

HTMLon and HTMLoff specify how Rpad interprets results (either HTML or text). Rpad output sections are normally rendered as plain text with a fixed-width font, so text script outputs are formatted properly. The output blocks can also contain HTML codes for displaying images or for formatting blocks. To change to HTML formatting, use HTMLon() (which sends '<htmlon/>' to the output). To turn HTML mode off, use HTMLoff() (which sends '<htmloff/>'). HTMLon and HTMLoff only apply to the existing Rpad input section; they don't carry over into the next.

HtmlTree and its shortcut H generates HTML (or other XML-like syntax) for an arbitrary tag with the specified name and arguments. Unnamed parameters to H are content, and named parameters are tag attributes. By using nesting, it's a good way to generate HTML (or any XML) with properly formed tags. If tagName is NULL, then the contents are created without a surrounding tag. For vectors, each vector element becomes surrounded by tags, so H("div", c(1,2,3)) results in <div>1</div><div>2</div><div>3</div>.

Html converts an R object to class HtmlTree. Methods are defined for matrices and data frames. For data frames, all ... arguments are passed to format before conversion to an HTML representation. Unnamed parameters to H that have a method defined for Html are automatically converted. For example, H("div", data.frame(a=1:2, b=1:2)) is the HTML representation of the data frame wrapped by a div tag.

For conversion of a wider selection of R objects to HTML, use HTML from the R2HTML package. HTML differs from Html in that HTML uses cat to directly send output whereas Html returns a character string. HfromHTML captures the output of HTML and returns it as a character string of class HtmlTree. This is useful for nesting HTML inside of H trees.

ROutputMode changes how R behaves with automatic printing. Possible values are: "text" (the default), "html", or "none". "text" is like at the command line: values returned in the script are automatically printed (without an explicit print statement) in standard text format. With "html", values returned are automatically printed, but HTML output is generated by using the HTML method from R2HTML (if available) instead of the print method. ROutputMode applies to all subsequent Rpad input section, including a rollover back to the beginning when a page is run several times.

Value

All of the HTML code generation routines return a character string of class HtmlTree. With automatic printing, the string is sent to the output (with cat). This has the effect that the HTML is displayed in Rpad. Note that if a HTML generation function is used inside of a loop or other scenario where the function results are not automatically printed, then you need to enclose the function with cat or print.

HTMLargs returns a string with the arguments as "a='arg1' b='arg2'", and so on. Note the use of single quotes. This will affect how quoted strings should be passed as elements.

Author(s)

Tom Short, EPRI, (tshort@epri.com)

See Also

R2HTML for other useful HTML routines that can be used in Rpad.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
  a <- data.frame(x = 1:10, y = (1:10)^3)

  # generate some GUI elements
  # - normally done in an Rpad input section with rpadRun="init"
  # switch to html mode
  HTMLon()
  data(state)
  # generate the select box
  HTMLselect("favoriteAmericanState", state.name)

  # using the H() function
  # a heading
  H("h2", "Arizona")

  # a simple div: "<div>Hello world</div>"
  H("div", "Hello world")
  # a div with a class
  # "<div class='helloStyle'>Hello world</div>"
  H("div", class="helloStyle", "Hello world")

  # you can nest them:
  H("div", class = "myClass", dojoType = "tree",
    "This is some text in the div ",  
    H("em", "emphasized"), "plus some more",
    "and more",
    H("div", class = "anotherClass",
      "text in the div",
      c(1,5,8)))

  # switch to text mode
  HTMLoff()
  summary(a)

  # fancy HTML output with R2HTML
  if (require(R2HTML)) {
    HTMLon()
    .HTML.file = "" # not needed in normal use
                    # kludge to pass R CMD check
    HTML(summary(a))
    HTMLoff()
  }

Rpad documentation built on May 2, 2019, 4:43 p.m.