0

I want to upload an .xlsx file to Shiny and load all the tabs in as a list. In the example, I am expecting the object input_file to be a list of dataframes which are the tabs from the .xlsx file. The example is selecting the first dataframe and then putting it in a flextable. The code doesnt work, I get the error message, object of type 'closure' is not subsettable Can anyone suggest anything to fix this?

library(shiny)
library(readxl)
library(flextable)
library(tidyverse)

ui<-shinyUI(fluidPage(
  titlePanel("Use readxl"),
  sidebarLayout(
    sidebarPanel(
      fileInput('file1', 'Choose xlsx file',
                accept = c(".xlsx")
      )
    ),
    mainPanel(
      
      htmlOutput ("ftable2")
     
    )
  )
)

)


server <- function(input, output){
  input_file<-reactive({
    if (is.null(input$file1)) {
      return("")
    }
    
    sapply(readxl::excel_sheets(input$file1$datapath), simplify = F, USE.NAMES = T,
           function(X) readxl::read_excel(input$file1$datapath, sheet = X))
    
    
  })
  
  output$ftable2<- renderUI( { 
    req(input_file())
    
    input_file[[1]]%>%
      head(10)%>%
      flextable()%>%
      htmltools_value()
  })}
shinyApp(ui, server)
Basil
  • 747
  • 7
  • 18
  • 1
    You need to use `()` to get the current value of a reactive element. So it should be `input_file()[[1]]` – MrFlick Dec 13 '22 at 20:50
  • I don't think this question was a duplicate, I included the error message to help troubleshooting this particular code rather than to look for a generic answer for the error message. – Basil Dec 14 '22 at 09:34
  • If you want to fix the "object of type 'closure' is not subsettable" error, then the duplicate is how to do that. If you get another error after you fix that, then ask a question about that. Right now we really can't run and test this code because it requires uploading excel files we don't have access to. – MrFlick Dec 14 '22 at 14:41
  • It is a generic upload, it would work with any excel file. – Basil Dec 15 '22 at 12:45

0 Answers0