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:
- Render the plot object using
renderPlot({p})
. - Assign the rendered plot to
output$x
. - Display the plot in the UI using
plotOutput("x")
.
The shiny
and ggplot2
packages are pre-loaded for you.
This exercise is part of the course
Building Web Applications with Shiny in R
Exercise 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()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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)