Web Application Development with R Using Shiny by Chris Beeley
Author:Chris Beeley
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2018-09-26T09:47:38+00:00
server.R
The server.R file runs as follows:
function(input, output, session) { output$randomNumber = renderText({ theNumber = sample(1:input$pickNumber, 1) session$sendCustomMessage(type = 'sendMessage',
message = theNumber) return(theNumber) }) output$theMessage = renderText({ return(input$JsMessage) }) }
The first thing to note here is the use of function(input, output, session){...} instead of the function(input, output){...} that we are used to seeing. The addition of a session argument adds a considerable amount of functionality to Shiny applications. In this case, it allows us to send messages to JavaScript. There is more on the functionality of the session argument in the next chapter, Chapter 6, Dashboards.
The first function here carries out two tasks. First, it takes the number that the user selected on the slider and picks a random number between 1 and that number. It sends that number straight to JavaScript using the session$sendCustomMessage function (which the session argument we mentioned previously enables). The sendCustomMessage() function is defined within Shiny; it is placed after session$ in order to tie it to the session defined in the shinyServer(function(input, output, session){...}) function. Finally, it returns the number to Shiny, just like in a standard application, ready to be placed in the output slot, which ui.R sets up.
The second function receives the JavaScript message. It's very easy to access, the Shiny function within JavaScript writes it to the standard input$xxx variable name, which we are used to seeing throughout the book. As is now plain, a lot of the work in this application is being done within the JavaScript file. Let's take a look.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7782)
Grails in Action by Glen Smith Peter Ledbrook(7696)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(6566)
Azure Containers Explained by Wesley Haakman & Richard Hooper(6556)
Running Windows Containers on AWS by Marcio Morales(6087)
Kotlin in Action by Dmitry Jemerov(5066)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(4917)
Combating Crime on the Dark Web by Nearchos Nearchou(4499)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4414)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(4338)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4172)
The Age of Surveillance Capitalism by Shoshana Zuboff(3955)
Python for Security and Networking - Third Edition by José Manuel Ortega(3740)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3509)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3408)
Mastering Python for Networking and Security by José Manuel Ortega(3344)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3330)
Blockchain Basics by Daniel Drescher(3294)
Learn Wireshark by Lisa Bock(3262)
