Render table when user uploads csv file

Solution for Render table when user uploads csv file
is Given Below:

I was wondering how to create a table with all the data from the user’s csv file. I would like the data to be uploaded into a tabPanel. Currently, I am running into the issue that no data is being displayed.

library(shiny)

ui <- fluidPage(

  navbarPage("Dashboard",

             tabPanel(title = "Model",
                      sidebarLayout(
                        sidebarPanel(

                              fileInput("file1", "Choose .csv file", #add red asterisks to make this mandatory
                                        accept = c(
                                          "text/csv",
                                          "text/comma-separated-values,text/plain",
                                          ".csv"),
                            ),    

                        ),

                        mainPanel(
                          tabsetPanel(
                            tabPanel("Data",
                                     tableOutput("tableOne"))

                          )
                        )    
                      )    
             )
)
)
            
server <- function(input,output){

  data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()}
    read.table(file=file1$datapath)

  })

  output$filedf <- renderTable({
    if(is.null(data())){return ()}
    input$file
  })

  output$tableOne <- renderTable({
    if(is.null(data())){return ()}
    data()
  })

  output$data <- renderTable(output$tableOne)

}


shinyApp(ui,server)

I’m not sure why the output$data <- renderTable(output$tableOne is not allowing the data to be displayed.

The input should match i.e. file1 is the input and not just file

library(shiny)

ui <- fluidPage(
  
  navbarPage("Dashboard",
             
             tabPanel(title = "Model",
                      sidebarLayout(
                        sidebarPanel(
                          
                          fileInput("file1", "Choose .csv file", #add red asterisks to make this mandatory
                                    accept = c(
                                      "text/csv",
                                      "text/comma-separated-values,text/plain",
                                      ".csv"),
                          ),    
                          
                        ),
                        
                        mainPanel(
                          tabsetPanel(
                            tabPanel("Data",
                                     tableOutput("tableOne"))
                            
                          )
                        )    
                      )    
             )
  )
)

server <- function(input,output){
  
  data <- reactive({
    req(input$file1)
    file1 <- input$file1
    if(is.null(file1)){return()}
    read.table(file=file1$datapath)
    
  })
  
 
  
  output$tableOne <- renderTable({
    req(input$file1)
    if(is.null(data())){return ()}
    data()
  })
  
  #output$data <- renderTable(output$tableOne)
  
}


shinyApp(ui,server)

-output

enter image description here