Help with simple Shiny Table

New to R Studio and Shiny. I am trying to build a simple table as shown..

Here is my code, I think the UI is correct for the most part I just don't really know what to put in for the server.
I need to make it so that whatever you put in for the input only renders that number of rows from the mpg data.frame.

library(shiny)
library(ggplot2)

          ui <- fluidPage( 
            # Application title 
            
            titlePanel("Homework 3"), 
            sidebarLayout(
              sidebarPanel( 
                numericInput(inputId = "n", 
                             label = "Number of Observations", 
                             value = 6, 
                             min = 0, 
                             max = 20) 
              ), 

              mainPanel( 
                
                tableOutput(outputId = "table") 
              ) 
            ) 
          ) 
          
          # Define server logic required 
          server <- function(input, output) { 
            output$table <- renderPrint({ 
             
             #NEED HELP HERE
              #THANKS
            
              })
          }
           
          # Run the application  
          shinyApp(ui = ui, server = server)

Hello cs43596

Please try:

output$table <- renderTable({
head(mpg, 6)
})

3 Likes

Updating @JoeMark 's example to use the number input

output$table <- renderTable({
  head(mpg, input$n)
})
1 Like