mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-29 03:00:45 -04:00
280 lines
16 KiB
HTML
280 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Session object — session • shiny</title><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"><script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"><script src="../pkgdown.js"></script><meta property="og:title" content="Session object — session"><meta property="og:description" content="Shiny server functions can optionally include session as a parameter
|
|
(e.g. function(input, output, session)). The session object is an
|
|
environment that can be used to access information and functionality
|
|
relating to the session. The following list describes the items available
|
|
in the environment; they can be accessed using the $ operator (for
|
|
example, session$clientData$url_search)."><meta property="og:image" content="/logo.png"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
|
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
|
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
|
<![endif]--></head><body data-spy="scroll" data-target="#toc">
|
|
|
|
|
|
<div class="container template-reference-topic">
|
|
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
|
|
<span class="sr-only">Toggle navigation</span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
<span class="navbar-brand">
|
|
<a class="navbar-link" href="../index.html">shiny</a>
|
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">1.12.0.9000</span>
|
|
</span>
|
|
</div>
|
|
|
|
<div id="navbar" class="navbar-collapse collapse">
|
|
<ul class="nav navbar-nav"><li>
|
|
<a href="../reference/index.html">Reference</a>
|
|
</li>
|
|
<li>
|
|
<a href="../news/index.html">Changelog</a>
|
|
</li>
|
|
</ul><ul class="nav navbar-nav navbar-right"><li>
|
|
<a href="https://github.com/rstudio/shiny/" class="external-link">
|
|
<span class="fab fa-github fa-lg"></span>
|
|
|
|
</a>
|
|
</li>
|
|
</ul></div><!--/.nav-collapse -->
|
|
</div><!--/.container -->
|
|
</div><!--/.navbar -->
|
|
|
|
|
|
|
|
</header><div class="row">
|
|
<div class="col-md-9 contents">
|
|
<div class="page-header">
|
|
<h1>Session object</h1>
|
|
<small class="dont-index">Source: <a href="https://github.com/rstudio/shiny/blob/rc-v1.12.1/R/shiny.R" class="external-link"><code>R/shiny.R</code></a></small>
|
|
<div class="hidden name"><code>session.Rd</code></div>
|
|
</div>
|
|
|
|
<div class="ref-description">
|
|
<p>Shiny server functions can optionally include <code>session</code> as a parameter
|
|
(e.g. <code>function(input, output, session)</code>). The session object is an
|
|
environment that can be used to access information and functionality
|
|
relating to the session. The following list describes the items available
|
|
in the environment; they can be accessed using the <code>$</code> operator (for
|
|
example, <code>session$clientData$url_search</code>).</p>
|
|
</div>
|
|
|
|
|
|
<div id="value">
|
|
<h2>Value</h2>
|
|
|
|
|
|
<dl><dt>allowReconnect(value)</dt>
|
|
<dd><p>If <code>value</code> is <code>TRUE</code> and run in a hosting environment (Shiny
|
|
Server or Connect) with reconnections enabled, then when the session ends
|
|
due to the network connection closing, the client will attempt to
|
|
reconnect to the server. If a reconnection is successful, the browser will
|
|
send all the current input values to the new session on the server, and
|
|
the server will recalculate any outputs and send them back to the client.
|
|
If <code>value</code> is <code>FALSE</code>, reconnections will be disabled (this is
|
|
the default state). If <code>"force"</code>, then the client browser will always
|
|
attempt to reconnect. The only reason to use <code>"force"</code> is for testing
|
|
on a local connection (without Shiny Server or Connect).</p></dd>
|
|
|
|
<dt>clientData</dt>
|
|
<dd><p>A <code><a href="reactiveValues.html">reactiveValues()</a></code> object that contains information about the client.</p><ul><li><p><code>pixelratio</code> reports the "device pixel ratio" from the web browser,
|
|
or 1 if none is reported. The value is 2 for Apple Retina displays.</p></li>
|
|
<li><p><code>singletons</code> - for internal use</p></li>
|
|
<li><p><code>url_protocol</code>, <code>url_hostname</code>, <code>url_port</code>,
|
|
<code>url_pathname</code>, <code>url_search</code>, <code>url_hash_initial</code>
|
|
and <code>url_hash</code> can be used to get the components of the URL
|
|
that was requested by the browser to load the Shiny app page.
|
|
These values are from the browser's perspective, so neither HTTP
|
|
proxies nor Shiny Server will affect these values. The
|
|
<code>url_search</code> value may be used with <code><a href="parseQueryString.html">parseQueryString()</a></code>
|
|
to access query string parameters.</p></li>
|
|
</ul><p><code>clientData</code> also contains information about each output.
|
|
<code>output_<var>outputId</var>_width</code> and <code>output_<var>outputId</var>_height</code>
|
|
give the dimensions (using <code>offsetWidth</code> and <code>offsetHeight</code>) of
|
|
the DOM element that is bound to <code><var>outputId</var></code>, and
|
|
<code>output_<var>outputId</var>_hidden</code> is a logical that indicates whether
|
|
the element is hidden. These values may be <code>NULL</code> if the output is
|
|
not bound.</p></dd>
|
|
|
|
<dt>input</dt>
|
|
<dd><p>The session's <code>input</code> object (the same as is passed into the Shiny
|
|
server function as an argument).</p></dd>
|
|
|
|
<dt>isClosed()</dt>
|
|
<dd><p>A function that returns <code>TRUE</code> if the client has
|
|
disconnected.</p></dd>
|
|
|
|
<dt>ns(id)</dt>
|
|
<dd><p>Server-side version of <code><a href="NS.html">ns <- NS(id)</a></code>. If bare IDs need to be
|
|
explicitly namespaced for the current module, <code>session$ns("name")</code>
|
|
will return the fully-qualified ID.</p></dd>
|
|
|
|
<dt>onEnded(callback)</dt>
|
|
<dd><p>Synonym for <code>onSessionEnded</code>.</p></dd>
|
|
|
|
<dt>onFlush(func, once=TRUE)</dt>
|
|
<dd><p>Registers a function to be called before the next time (if <code>once=TRUE</code>)
|
|
or every time (if <code>once=FALSE</code>) Shiny flushes the reactive system.
|
|
Returns a function that can be called with no arguments to cancel the
|
|
registration.</p></dd>
|
|
|
|
<dt>onFlushed(func, once=TRUE)</dt>
|
|
<dd><p>Registers a function to be called after the next time (if <code>once=TRUE</code>)
|
|
or every time (if <code>once=FALSE</code>) Shiny flushes the reactive system.
|
|
Returns a function that can be called with no arguments to cancel the
|
|
registration.</p></dd>
|
|
|
|
<dt>onSessionEnded(callback)</dt>
|
|
<dd><p>Registers a function to be called after the client has disconnected.
|
|
Returns a function that can be called with no arguments to cancel the
|
|
registration.</p></dd>
|
|
|
|
<dt>output</dt>
|
|
<dd><p>The session's <code>output</code> object (the same as is passed into the Shiny
|
|
server function as an argument).</p></dd>
|
|
|
|
<dt>reactlog</dt>
|
|
<dd><p>For internal use.</p></dd>
|
|
|
|
<dt>registerDataObj(name, data, filterFunc)</dt>
|
|
<dd><p>Publishes any R object as a URL endpoint that is unique to this session.
|
|
<code>name</code> must be a single element character vector; it will be used
|
|
to form part of the URL. <code>filterFunc</code> must be a function that takes
|
|
two arguments: <code>data</code> (the value that was passed into
|
|
<code>registerDataObj</code>) and <code>req</code> (an environment that implements
|
|
the Rook specification for HTTP requests). <code>filterFunc</code> will be
|
|
called with these values whenever an HTTP request is made to the URL
|
|
endpoint. The return value of <code>filterFunc</code> should be a Rook-style
|
|
response.</p></dd>
|
|
|
|
<dt>reload()</dt>
|
|
<dd><p>The equivalent of hitting the browser's Reload button. Only works if the
|
|
session is actually connected.</p></dd>
|
|
|
|
<dt>request</dt>
|
|
<dd><p>An environment that implements the <a href="https://github.com/jeffreyhorner/Rook#the-environment" class="external-link">Rook specification</a> for
|
|
HTTP requests. This is the request that was used to initiate the websocket
|
|
connection (as opposed to the request that downloaded the web page for the
|
|
app).</p></dd>
|
|
|
|
<dt>userData</dt>
|
|
<dd><p>An environment for app authors and module/package authors to store whatever
|
|
session-specific data they want.</p></dd>
|
|
|
|
<dt>user</dt>
|
|
<dd><p>User's log-in information. Useful for identifying users on hosted platforms
|
|
such as RStudio Connect and Shiny Server.</p></dd>
|
|
|
|
<dt>groups</dt>
|
|
<dd><p>The <code>user</code>'s relevant group information. Useful for determining what
|
|
privileges the user should or shouldn't have.</p></dd>
|
|
|
|
<dt>resetBrush(brushId)</dt>
|
|
<dd><p>Resets/clears the brush with the given <code>brushId</code>, if it exists on
|
|
any <code>imageOutput</code> or <code>plotOutput</code> in the app.</p></dd>
|
|
|
|
<dt>sendCustomMessage(type, message)</dt>
|
|
<dd><p>Sends a custom message to the web page. <code>type</code> must be a
|
|
single-element character vector giving the type of message, while
|
|
<code>message</code> can be any jsonlite-encodable value. Custom messages
|
|
have no meaning to Shiny itself; they are used solely to convey information
|
|
to custom JavaScript logic in the browser. You can do this by adding
|
|
JavaScript code to the browser that calls
|
|
<code>Shiny.addCustomMessageHandler(type, function(message){...})</code>
|
|
as the page loads; the function you provide to
|
|
<code>addCustomMessageHandler</code> will be invoked each time
|
|
<code>sendCustomMessage</code> is called on the server.</p></dd>
|
|
|
|
<dt>sendBinaryMessage(type, message)</dt>
|
|
<dd><p>Similar to <code>sendCustomMessage</code>, but the message must be a raw vector
|
|
and the registration method on the client is
|
|
<code>Shiny.addBinaryMessageHandler(type, function(message){...})</code>. The
|
|
message argument on the client will be a
|
|
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="external-link">DataView</a>.</p></dd>
|
|
|
|
<dt>sendInputMessage(inputId, message)</dt>
|
|
<dd><p>Sends a message to an input on the session's client web page; if the input
|
|
is present and bound on the page at the time the message is received, then
|
|
the input binding object's <code>receiveMessage(el, message)</code> method will
|
|
be called. <code>sendInputMessage</code> should generally not be called directly
|
|
from Shiny apps, but through friendlier wrapper functions like
|
|
<code><a href="updateTextInput.html">updateTextInput()</a></code>.</p></dd>
|
|
|
|
<dt>setBookmarkExclude(names)</dt>
|
|
<dd><p>Set input names to be excluded from bookmarking.</p></dd>
|
|
|
|
<dt>getBookmarkExclude()</dt>
|
|
<dd><p>Returns the set of input names to be excluded from bookmarking.</p></dd>
|
|
|
|
<dt>onBookmark(fun)</dt>
|
|
<dd><p>Registers a function that will be called just before bookmarking state.</p></dd>
|
|
|
|
<dt>onBookmarked(fun)</dt>
|
|
<dd><p>Registers a function that will be called just after bookmarking state.</p></dd>
|
|
|
|
<dt>onRestore(fun)</dt>
|
|
<dd><p>Registers a function that will be called when a session is restored, before
|
|
all other reactives, observers, and render functions are run.</p></dd>
|
|
|
|
<dt>onRestored(fun)</dt>
|
|
<dd><p>Registers a function that will be called when a session is restored, after
|
|
all other reactives, observers, and render functions are run.</p></dd>
|
|
|
|
<dt>doBookmark()</dt>
|
|
<dd><p>Do bookmarking and invoke the onBookmark and onBookmarked callback functions.</p></dd>
|
|
|
|
<dt>exportTestValues()</dt>
|
|
<dd><p>Registers expressions for export in test mode, available at the test
|
|
snapshot URL.</p></dd>
|
|
|
|
<dt>getTestSnapshotUrl(input=TRUE, output=TRUE, export=TRUE,
|
|
format="json")</dt>
|
|
<dd><p>Returns a URL for the test snapshots. Only has an effect when the
|
|
<code>shiny.testmode</code> option is set to TRUE. For the input, output, and
|
|
export arguments, TRUE means to return all of these values. It is also
|
|
possible to specify by name which values to return by providing a
|
|
character vector, as in <code>input=c("x", "y")</code>. The format can be
|
|
"rds" or "json".</p></dd>
|
|
|
|
<dt>setCurrentTheme(theme)</dt>
|
|
<dd><p>Sets the current <code><a href="bootstrapLib.html">bootstrapLib()</a></code> theme, which updates the value of
|
|
<code><a href="getCurrentTheme.html">getCurrentTheme()</a></code>, invalidates <code>session$getCurrentTheme()</code>, and calls
|
|
function(s) registered with <code><a href="registerThemeDependency.html">registerThemeDependency()</a></code> with provided
|
|
<code>theme</code>. If those function calls return <code><a href="https://rstudio.github.io/htmltools/reference/htmlDependency.html" class="external-link">htmltools::htmlDependency()</a></code>s with
|
|
<code>stylesheet</code>s, then those stylesheets are "refreshed" (i.e., the new
|
|
stylesheets are inserted on the page and the old ones are disabled and
|
|
removed).</p></dd>
|
|
|
|
<dt>getCurrentTheme()</dt>
|
|
<dd><p>A reactive read of the current <code><a href="bootstrapLib.html">bootstrapLib()</a></code> theme.</p></dd>
|
|
|
|
</dl></div>
|
|
|
|
</div>
|
|
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
|
|
<nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
|
|
</nav></div>
|
|
</div>
|
|
|
|
|
|
<footer><div class="copyright">
|
|
<p></p><p>Developed by Winston Chang, Joe Cheng, JJ Allaire, Carson Sievert, Barret Schloerke, Garrick Aden-Buie, Yihui Xie, Jeff Allen, Jonathan McPherson, Alan Dipert, Barbara Borges, Posit Software, PBC.</p>
|
|
</div>
|
|
|
|
<div class="pkgdown">
|
|
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.2.0.</p>
|
|
</div>
|
|
|
|
</footer></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</body></html>
|
|
|