Tina
Tina

Reputation: 31

Shiny Rstudio upload xlsx file

I am trying to upload an xlsx file using shiny rstudio. But the data can't be read in. Can anyone help me figure it out?

ui <- fluidPage(titlePanel("AFSI Data Reformat"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose xlsx file',
            accept = c(".xlsx"))),
mainPanel(
tableOutput('file2'))))
Server(function(input, output) {
output$file2 <- renderTable({
inFile <- input$file1
if(is.null(inFile))
return(NULL)
read_excel(paste(inFile$datapath, ".xlsx", sep=""), 1)})

When I clicked 'Run App', and the tried to upload an xlsx file, it shows nothing was read in, 'No file uploaded'.

Upvotes: 3

Views: 2970

Answers (1)

HubertL
HubertL

Reputation: 19544

Works fine for me after removing the instruction that adds a second ".xlsx" extension to file name :

ui <- fluidPage(titlePanel("AFSI Data Reformat"),
                sidebarLayout(sidebarPanel(
                  fileInput('file1', 'Choose xlsx file',
                            accept = c(".xlsx"))
                ),
                mainPanel(tableOutput('file2'))))

server <- function(input, output) {
  output$file2 <- renderTable({
    inFile <- input$file1
    if (is.null(inFile))
      return(NULL)
    readxl::read_excel(inFile$datapath)
  })
}

shinyApp(ui, server)

Upvotes: 4

Related Questions