File: ClientValue.Rd

package info (click to toggle)
r-cran-crosstalk 1.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: javascript: 1,697; sh: 15; makefile: 7
file content (122 lines) | stat: -rw-r--r-- 3,906 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/crosstalk.R
\name{ClientValue}
\alias{ClientValue}
\title{ClientValue object}
\description{
An object that can be used in a \href{https://shiny.posit.co/}{Shiny} server
function to get or set a crosstalk variable that exists on the client. The
client copy of the variable is the canonical copy, so there is no direct
"set" method that immediately changes the value; instead, there is a
`sendUpdate` method that sends a request to the browser to change the value,
which will then cause the new value to be relayed back to the server.

This object is used to implement \code{\link{SharedData}} and should not need
to be used directly by users.
}
\examples{
library(shiny)

server <- function(input, output, session) {
  cv <- ClientValue$new("var1", "group1")

  r <- reactive({
    # Don't proceed unless cv$get() is a non-NULL value
    validate(need(cv$get(), message = FALSE))

    runif(cv$get())
  })

  observeEvent(input$click, {
    cv$sendUpdate(NULL)
  })
}

}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-ClientValue-new}{\code{ClientValue$new()}}
\item \href{#method-ClientValue-get}{\code{ClientValue$get()}}
\item \href{#method-ClientValue-sendUpdate}{\code{ClientValue$sendUpdate()}}
\item \href{#method-ClientValue-clone}{\code{ClientValue$clone()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-ClientValue-new"></a>}}
\if{latex}{\out{\hypertarget{method-ClientValue-new}{}}}
\subsection{Method \code{new()}}{
Creates a new ClientValue object to reflect the crosstalk variable
specified by `group` and `name`.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{ClientValue$new(
  name,
  group = "default",
  session = shiny::getDefaultReactiveDomain()
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{name}}{The name of the crosstalk variable.}

\item{\code{group}}{The name of the crosstalk variable group.}

\item{\code{session}}{The Shiny session to connect to; defaults to the current
session.}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-ClientValue-get"></a>}}
\if{latex}{\out{\hypertarget{method-ClientValue-get}{}}}
\subsection{Method \code{get()}}{
Read the value. This is a reactive operation akin to reading a reactive
value, and so can only be done in a reactive context (e.g. in a
`shiny::reactive()`, `shiny::observe()`, or `shiny::isolate()` block).
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{ClientValue$get()}\if{html}{\out{</div>}}
}

}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-ClientValue-sendUpdate"></a>}}
\if{latex}{\out{\hypertarget{method-ClientValue-sendUpdate}{}}}
\subsection{Method \code{sendUpdate()}}{
Send a message to the browser asking it to update the crosstalk var to
the given value. This update does not happen synchronously, that is, a
call to `get()` immediately following `sendUpdate(value)` will not
reflect the new value.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{ClientValue$sendUpdate(value)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{value}}{The new value for the crosstalk variable. Must be
serializable as JSON using `jsonlite`.}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-ClientValue-clone"></a>}}
\if{latex}{\out{\hypertarget{method-ClientValue-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{ClientValue$clone(deep = FALSE)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}
}