CommencerCommencer gratuitement

Add output (UI/Server)

The next step in building your app is to add an empty plot as a placeholder. Recall that in order to add a plot p assigned to an object named x to a Shiny app, you need to:

  1. Render the plot object using renderPlot({p}).
  2. Assign the rendered plot to output$x.
  3. Display the plot in the UI using plotOutput("x").

The shiny and ggplot2 packages are pre-loaded for you.

Cet exercice fait partie du cours

Building Web Applications with Shiny in R

Afficher le cours

Instructions

  • Create an empty plot by calling ggplot(), render it, and assign it to an output named 'trend'.
  • Display the plot in the UI. Be sure to add a comma after textInput().

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

ui <- fluidPage(
  textInput('name', 'Enter Name', 'David')
  # CODE BELOW: Display the plot output named 'trend'
  
)

server <- function(input, output, session) {
  # CODE BELOW: Render an empty plot and assign to output named 'trend'
  
  
  
}

shinyApp(ui = ui, server = server)
Modifier et exécuter le code