Debian Codegraph @

man/session.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/shiny.R
3 \name{session}
4 \alias{session}
5 \title{Session object}
6 \value{
7 \item{allowReconnect(value)}{
8 If \code{value} is \code{TRUE} and run in a hosting environment (Shiny
9 Server or Connect) with reconnections enabled, then when the session ends
10 due to the network connection closing, the client will attempt to
11 reconnect to the server. If a reconnection is successful, the browser will
12 send all the current input values to the new session on the server, and
13 the server will recalculate any outputs and send them back to the client.
14 If \code{value} is \code{FALSE}, reconnections will be disabled (this is
15 the default state). If \code{"force"}, then the client browser will always
16 attempt to reconnect. The only reason to use \code{"force"} is for testing
17 on a local connection (without Shiny Server or Connect).
18 }
19 \item{clientData}{
20 A \code{\link[=reactiveValues]{reactiveValues()}} object that contains information about the client.
21 \itemize{
22 \item{\code{pixelratio} reports the "device pixel ratio" from the web browser,
23 or 1 if none is reported. The value is 2 for Apple Retina displays.
24 }
25 \item{\code{singletons} - for internal use}
26 \item{\code{url_protocol}, \code{url_hostname}, \code{url_port},
27 \code{url_pathname}, \code{url_search}, \code{url_hash_initial}
28 and \code{url_hash} can be used to get the components of the URL
29 that was requested by the browser to load the Shiny app page.
30 These values are from the browser's perspective, so neither HTTP
31 proxies nor Shiny Server will affect these values. The
32 \code{url_search} value may be used with \code{\link[=parseQueryString]{parseQueryString()}}
33 to access query string parameters.
34 }
35 }
36 \code{clientData} also contains information about each output.
37 \code{output_\var{outputId}_width} and \code{output_\var{outputId}_height}
38 give the dimensions (using \code{offsetWidth} and \code{offsetHeight}) of
39 the DOM element that is bound to \code{\var{outputId}}, and
40 \code{output_\var{outputId}_hidden} is a logical that indicates whether
41 the element is hidden. These values may be \code{NULL} if the output is
42 not bound.
43 }
44 \item{input}{
45 The session's \code{input} object (the same as is passed into the Shiny
46 server function as an argument).
47 }
48 \item{isClosed()}{A function that returns \code{TRUE} if the client has
49 disconnected.
50 }
51 \item{ns(id)}{
52 Server-side version of \code{\link[=NS]{ns <- NS(id)}}. If bare IDs need to be
53 explicitly namespaced for the current module, \code{session$ns("name")}
54 will return the fully-qualified ID.
55 }
56 \item{onEnded(callback)}{
57 Synonym for \code{onSessionEnded}.
58 }
59 \item{onFlush(func, once=TRUE)}{
60 Registers a function to be called before the next time (if \code{once=TRUE})
61 or every time (if \code{once=FALSE}) Shiny flushes the reactive system.
62 Returns a function that can be called with no arguments to cancel the
63 registration.
64 }
65 \item{onFlushed(func, once=TRUE)}{
66 Registers a function to be called after the next time (if \code{once=TRUE})
67 or every time (if \code{once=FALSE}) Shiny flushes the reactive system.
68 Returns a function that can be called with no arguments to cancel the
69 registration.
70 }
71 \item{onSessionEnded(callback)}{
72 Registers a function to be called after the client has disconnected.
73 Returns a function that can be called with no arguments to cancel the
74 registration.
75 }
76 \item{output}{
77 The session's \code{output} object (the same as is passed into the Shiny
78 server function as an argument).
79 }
80 \item{reactlog}{
81 For internal use.
82 }
83 \item{registerDataObj(name, data, filterFunc)}{
84 Publishes any R object as a URL endpoint that is unique to this session.
85 \code{name} must be a single element character vector; it will be used
86 to form part of the URL. \code{filterFunc} must be a function that takes
87 two arguments: \code{data} (the value that was passed into
88 \code{registerDataObj}) and \code{req} (an environment that implements
89 the Rook specification for HTTP requests). \code{filterFunc} will be
90 called with these values whenever an HTTP request is made to the URL
91 endpoint. The return value of \code{filterFunc} should be a Rook-style
92 response.
93 }
94 \item{reload()}{
95 The equivalent of hitting the browser's Reload button. Only works if the
96 session is actually connected.
97 }
98 \item{request}{
99 An environment that implements the \href{https://github.com/jeffreyhorner/Rook#the-environment}{Rook specification} for
100 HTTP requests. This is the request that was used to initiate the websocket
101 connection (as opposed to the request that downloaded the web page for the
102 app).
103 }
104 \item{userData}{
105 An environment for app authors and module/package authors to store whatever
106 session-specific data they want.
107 }
108 \item{user}{
109 User's log-in information. Useful for identifying users on hosted platforms
110 such as RStudio Connect and Shiny Server.
111 }
112 \item{groups}{
113 The \code{user}'s relevant group information. Useful for determining what
114 privileges the user should or shouldn't have.
115 }
116 \item{resetBrush(brushId)}{
117 Resets/clears the brush with the given \code{brushId}, if it exists on
118 any \code{imageOutput} or \code{plotOutput} in the app.
119 }
120 \item{sendCustomMessage(type, message)}{
121 Sends a custom message to the web page. \code{type} must be a
122 single-element character vector giving the type of message, while
123 \code{message} can be any jsonlite-encodable value. Custom messages
124 have no meaning to Shiny itself; they are used solely to convey information
125 to custom JavaScript logic in the browser. You can do this by adding
126 JavaScript code to the browser that calls
127 \code{Shiny.addCustomMessageHandler(type, function(message){...})}
128 as the page loads; the function you provide to
129 \code{addCustomMessageHandler} will be invoked each time
130 \code{sendCustomMessage} is called on the server.
131 }
132 \item{sendBinaryMessage(type, message)}{
133 Similar to \code{sendCustomMessage}, but the message must be a raw vector
134 and the registration method on the client is
135 \code{Shiny.addBinaryMessageHandler(type, function(message){...})}. The
136 message argument on the client will be a
137 \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView}{DataView}.
138 }
139 \item{sendInputMessage(inputId, message)}{
140 Sends a message to an input on the session's client web page; if the input
141 is present and bound on the page at the time the message is received, then
142 the input binding object's \code{receiveMessage(el, message)} method will
143 be called. \code{sendInputMessage} should generally not be called directly
144 from Shiny apps, but through friendlier wrapper functions like
145 \code{\link[=updateTextInput]{updateTextInput()}}.
146 }
147 \item{setBookmarkExclude(names)}{
148 Set input names to be excluded from bookmarking.
149 }
150 \item{getBookmarkExclude()}{
151 Returns the set of input names to be excluded from bookmarking.
152 }
153 \item{onBookmark(fun)}{
154 Registers a function that will be called just before bookmarking state.
155 }
156 \item{onBookmarked(fun)}{
157 Registers a function that will be called just after bookmarking state.
158 }
159 \item{onRestore(fun)}{
160 Registers a function that will be called when a session is restored, before
161 all other reactives, observers, and render functions are run.
162 }
163 \item{onRestored(fun)}{
164 Registers a function that will be called when a session is restored, after
165 all other reactives, observers, and render functions are run.
166 }
167 \item{doBookmark()}{
168 Do bookmarking and invoke the onBookmark and onBookmarked callback functions.
169 }
170 \item{exportTestValues()}{
171 Registers expressions for export in test mode, available at the test
172 snapshot URL.
173 }
174 \item{getTestSnapshotUrl(input=TRUE, output=TRUE, export=TRUE,
175 format="json")}{
176 Returns a URL for the test snapshots. Only has an effect when the
177 \code{shiny.testmode} option is set to TRUE. For the input, output, and
178 export arguments, TRUE means to return all of these values. It is also
179 possible to specify by name which values to return by providing a
180 character vector, as in \code{input=c("x", "y")}. The format can be
181 "rds" or "json".
182 }
183 \item{setCurrentTheme(theme)}{
184 Sets the current \code{\link[=bootstrapLib]{bootstrapLib()}} theme, which updates the value of
185 \code{\link[=getCurrentTheme]{getCurrentTheme()}}, invalidates \code{session$getCurrentTheme()}, and calls
186 function(s) registered with \code{\link[=registerThemeDependency]{registerThemeDependency()}} with provided
187 \code{theme}. If those function calls return \code{\link[htmltools:htmlDependency]{htmltools::htmlDependency()}}s with
188 \code{stylesheet}s, then those stylesheets are "refreshed" (i.e., the new
189 stylesheets are inserted on the page and the old ones are disabled and
190 removed).
191 }
192 \item{getCurrentTheme()}{
193 A reactive read of the current \code{\link[=bootstrapLib]{bootstrapLib()}} theme.
194 }
195 }
196 \description{
197 Shiny server functions can optionally include \code{session} as a parameter
198 (e.g. \verb{function(input, output, session)}). The session object is an
199 environment that can be used to access information and functionality
200 relating to the session. The following list describes the items available
201 in the environment; they can be accessed using the \code{$} operator (for
202 example, \code{session$clientData$url_search}).
203 }