Reputation: 4995
I am very new to shiny and ran quite fast in a problem which impedes to continue my work. I created a .xlsx file and tried to load this within shiny. A similar problem was dicussed here but was not finally solved.
I tried to keep the code as simple as possible:
library(shiny)
ui <- fluidPage(
fileInput("uploadFile", "XLSX file"),
verbatimTextOutput("summary")
)
server <- function(input, output) ({
dataset<-reactive({
inFile <- input$uploadFile
dat<-read.xlsx("inFile$datapath", 1)
return(dat)
})
output$summary <- renderText({summary(dataset())})
})
Just loading the .xlsx file in R works fine with this code:
read.xlsx("testdata.xlsx", 1)
Adding browser()
after inFile <- input$uploadFile
in server
and calling inFile
gives I think the correct object which contains .$datapath
.
The error I get after uploading the file is:
Error in loadWorkbook(file) : Cannot find inFile$datapath
I hope this is not to silly but I just can figure out how to solve it. What I would like to know is how can I store my uploaded file as a dataframe within shiny?
Upvotes: 1
Views: 3360
Reputation: 180
You should leave the "" from the dat<-read.xlsx("inFile$datapath", 1)
line.
This one works:
dat<-read.xlsx(inFile$datapath, 1)
Best, Róbert
Upvotes: 2