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)