Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ClientValue

ClientValue object


Description

An object that can be used in a 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 SharedData and should not need to be used directly by users.

Methods

Public methods


Method new()

Creates a new ClientValue object to reflect the crosstalk variable specified by 'group' and 'name'.

Usage
ClientValue$new(
  name,
  group = "default",
  session = shiny::getDefaultReactiveDomain()
)
Arguments
name

The name of the crosstalk variable.

group

The name of the crosstalk variable group.

session

The Shiny session to connect to; defaults to the current session.


Method 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).

Usage
ClientValue$get()

Method 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.

Usage
ClientValue$sendUpdate(value)
Arguments
value

The new value for the crosstalk variable. Must be serializable as JSON using 'jsonlite'.


Method clone()

The objects of this class are cloneable with this method.

Usage
ClientValue$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

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)
  })
}

crosstalk

Inter-Widget Interactivity for HTML Widgets

v1.1.1
MIT + file LICENSE
Authors
Joe Cheng [aut], Carson Sievert [aut, cre] (<https://orcid.org/0000-0002-4958-2844>), RStudio [cph], jQuery Foundation [cph] (jQuery library and jQuery UI library), jQuery contributors [ctb, cph] (jQuery library; authors listed in inst/www/shared/jquery-AUTHORS.txt), Mark Otto [ctb] (Bootstrap library), Jacob Thornton [ctb] (Bootstrap library), Bootstrap contributors [ctb] (Bootstrap library), Twitter, Inc [cph] (Bootstrap library), Brian Reavis [ctb, cph] (selectize.js library), Kristopher Michael Kowal [ctb, cph] (es5-shim library), es5-shim contributors [ctb, cph] (es5-shim library), Denis Ineshin [ctb, cph] (ion.rangeSlider library), Sami Samhuri [ctb, cph] (Javascript strftime library)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.