Reading client information and GET requests in Shiny

Shiny includes some very useful functionality that allows you to read information from a client's web browser, such as information from the URL (including GET search requests) and the size of plots in pixels.

All you need to do, as before, is run shinyServer() with a session argument. This causes, among other things, an object to be created that holds information about a client's session, named session$clientData.

The exact content of this object will depend on what is open on the screen. The following objects will always exist:

url_hostname   # hostname, e.g. localhost or chrisbeeley.net  
url_pathname = # path, e.g. / or /shiny  
url_port =     # port number (8100 for localhost, can optionally  
               # change when hosting, see chapter 5)  
url_protocol = # highly likely to be http:  
url_search =   # the text after the "?" in the URL. In the 
following
# example this will read "?person=NHS&smooth=yes".

Different output types will yield different information. Plots will give the following information, among other return values:

output_myplot_height = # in pixels  
output_myplot_width =  # in pixels  

There are many applications to which this information can be put, such as giving different UIs or default settings to users from different domains, or configuring graphs and other output based on their size (for example, for users who are using mobile devices or 32" monitors). We're going to look at perhaps the most obvious and powerful use of client data: the search string.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.169.100