Argument error - tabsetPanel

Hello,
I have to create an App on a tab that can read an uploaded .txt or .xlsx file and then plot the values on the screen. I'm getting this error and I don't know what do to :cold_sweat:
Please, someone help me! I'm doing this for a college internship activity

ui:

      tabPanel("Plot txt", verbatimTextOutput("plottxt"),
               sidebarLayout(
                 sidebarPanel(
                   fileInput("file1", "Upload do Arquivo",
                             accept = c(
                               "text/xlsx",
                               "text/comma-separated-values,text/plain",
                               ".xlsx")
                   ),
                   tags$hr(),
                   checkboxInput("header", "Header", TRUE)
                 ),
                 mainPanel(
                   tableOutput("contents")
                 )
               )
            )

server:

  output$contents <- renderTable({

    inFile <- input$file1
    
    if (is.null(inFile))
      return(NULL)
    
    read.xlsx(inFile$datapath, header = input$header)
  })

error:

Listening on http://127.0.0.1:6044
Warning: Error in read.xlsx: unused argument (header = input$header)
  96: renderTable [C:\Users\Usuario\Desktop\Nando\R\Shiny com abas/app.R#133]
  95: func
  82: origRenderFunc
  81: output$contents
   1: runApp

Hi @nandoeab!

You’ve passed a header argument to read.xlsx(), but it doesn’t take any arguments with that name. Are you thinking of read.csv()?

If you want your app to be able to handle both .xlsx files and .txt files, you’ll probably need to add logic to determine which kind of file got uploaded, and then use the appropriate function to read it in.

read.xlsx() requires you to provide a sheet name or index, but besides that I can't reproduce your issue with this code.

library(shiny)
library(xlsx)

ui <- tabPanel("Plot txt", verbatimTextOutput("plottxt"),
               sidebarLayout(
                 sidebarPanel(
                   fileInput("file1", "Upload do Arquivo",
                             accept = c(
                               "text/xlsx",
                               "text/comma-separated-values,text/plain",
                               ".xlsx")
                   ),
                   tags$hr(),
                   checkboxInput("header", "Header", TRUE)
                 ),
                 mainPanel(
                   tableOutput("contents")
                 )
               )
)

server <- function(input, output, session) {
  output$contents <- renderTable({
    inFile <- input$file1
    
    if (is.null(inFile))
      return(NULL)
    
    read.xlsx(inFile$datapath,
              header = input$header,
              sheetIndex = 1)
  })
}

shinyApp(ui, server)

Since @nandoeab has not provided a reprex we are thinking on different packages, xlsx::read.xlsx() has the header argument, maybe that confusion is the problem.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.