server.R

Let's take a quick look at the server.R file, shown in the following code:

function(input, output) { 
  output$textDisplay <- renderText({ 
    paste0("Title:'", input$comment, 
      "'. There are ", nchar(input$comment), 
      " characters in this." 
    ) 
  }) 
 
  output$plotDisplay <- renderPlot({ 
    par(bg = "#ecf1ef") # set the background color 
    plot(poly(1:100, as.numeric(input$graph)), type = "l", 
      ylab="y", xlab="x") 
  }) 
} 

Text handling is done as before. You'll note that the renderPlot() function begins by setting the background color to the same as the page itself (par(bg = "#ecf1ef"); for more graphical options in R, see ?par). You don't have to do this, but the graph's background will be visible as a big white square if you don't.

The actual plot itself ...

Get Web Application Development with R Using Shiny - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.