Debian Codegraph @

man/renderPrint.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/shinywrappers.R
3 \name{renderPrint}
4 \alias{renderPrint}
5 \alias{renderText}
6 \title{Text Output}
7 \usage{
8 renderPrint(
9 expr,
10 env = parent.frame(),
11 quoted = FALSE,
12 width = getOption("width"),
13 outputArgs = list()
14 )
15
16 renderText(
17 expr,
18 env = parent.frame(),
19 quoted = FALSE,
20 outputArgs = list(),
21 sep = " "
22 )
23 }
24 \arguments{
25 \item{expr}{An expression to evaluate.}
26
27 \item{env}{The parent environment for the reactive expression. By default,
28 this is the calling environment, the same as when defining an ordinary
29 non-reactive expression. If \code{expr} is a quosure and \code{quoted} is \code{TRUE},
30 then \code{env} is ignored.}
31
32 \item{quoted}{If it is \code{TRUE}, then the \code{\link[=quote]{quote()}}ed value of \code{expr}
33 will be used when \code{expr} is evaluated. If \code{expr} is a quosure and you
34 would like to use its expression as a value for \code{expr}, then you must set
35 \code{quoted} to \code{TRUE}.}
36
37 \item{width}{Width of printed output.}
38
39 \item{outputArgs}{A list of arguments to be passed through to the implicit
40 call to \code{\link[=verbatimTextOutput]{verbatimTextOutput()}} or \code{\link[=textOutput]{textOutput()}} when the functions are
41 used in an interactive RMarkdown document.}
42
43 \item{sep}{A separator passed to \code{cat} to be appended after each
44 element.}
45 }
46 \value{
47 For \code{renderPrint()}, note the given expression returns \code{NULL} then \code{NULL}
48 will actually be visible in the output. To display nothing, make your
49 function return \code{\link[=invisible]{invisible()}}.
50 }
51 \description{
52 \code{renderPrint()} prints the result of \code{expr}, while \code{renderText()} pastes it
53 together into a single string. \code{renderPrint()} is equivalent to \code{\link[=print]{print()}};
54 \code{renderText()} is equivalent to \code{\link[=cat]{cat()}}. Both functions capture all other
55 printed output generated while evaluating \code{expr}.
56
57 \code{renderPrint()} is usually paired with \code{\link[=verbatimTextOutput]{verbatimTextOutput()}};
58 \code{renderText()} is usually paired with \code{\link[=textOutput]{textOutput()}}.
59 }
60 \details{
61 The corresponding HTML output tag can be anything (though \code{pre} is
62 recommended if you need a monospace font and whitespace preserved) and should
63 have the CSS class name \code{shiny-text-output}.
64 }
65 \examples{
66 isolate({
67
68 # renderPrint captures any print output, converts it to a string, and
69 # returns it
70 visFun <- renderPrint({ "foo" })
71 visFun()
72 # '[1] "foo"'
73
74 invisFun <- renderPrint({ invisible("foo") })
75 invisFun()
76 # ''
77
78 multiprintFun <- renderPrint({
79 print("foo");
80 "bar"
81 })
82 multiprintFun()
83 # '[1] "foo"\n[1] "bar"'
84
85 nullFun <- renderPrint({ NULL })
86 nullFun()
87 # 'NULL'
88
89 invisNullFun <- renderPrint({ invisible(NULL) })
90 invisNullFun()
91 # ''
92
93 vecFun <- renderPrint({ 1:5 })
94 vecFun()
95 # '[1] 1 2 3 4 5'
96
97
98 # Contrast with renderText, which takes the value returned from the function
99 # and uses cat() to convert it to a string
100 visFun <- renderText({ "foo" })
101 visFun()
102 # 'foo'
103
104 invisFun <- renderText({ invisible("foo") })
105 invisFun()
106 # 'foo'
107
108 multiprintFun <- renderText({
109 print("foo");
110 "bar"
111 })
112 multiprintFun()
113 # 'bar'
114
115 nullFun <- renderText({ NULL })
116 nullFun()
117 # ''
118
119 invisNullFun <- renderText({ invisible(NULL) })
120 invisNullFun()
121 # ''
122
123 vecFun <- renderText({ 1:5 })
124 vecFun()
125 # '1 2 3 4 5'
126
127 })
128 }
129 \seealso{
130 \code{\link[=outputOptions]{outputOptions()}}
131 }