Web Application Development with R Using Shiny(Third Edition)
上QQ阅读APP看书,第一时间看更新

The program structure

Since the first edition of this book, a significant change has taken place with regards to how Shiny applications are structured. A new feature has been added, giving us the ability to place them all within one code file. This is most useful when building small demonstrations or examples for other users, who can just paste the whole code file into the console and have the application run automatically. In order to make use of this functionality, just combine the code from server.R and ui.R, as shown in the following example:

library(shiny) 
server <- function(input, output) { 
  #contents of server.R file 
} 
 
ui <- fluidPage( # or other layout function 
  # contents of ui.R file 
) 
shinyApp(ui = ui, server = server) 

This is useful neither for large applications, nor for the purposes of explaining the functions of particular parts of code within this book, so we shall ignore it from now on. Just be aware that it's possible; you may well come across it on forums, and you may wish to contribute some small examples yourself.