Wang
Wang

Reputation: 1460

R shinyFiles : Warning: Error in [: object of type 'closure' is not subsettable [No stack trace available]

I want to use shiny to select a local directory and output the files in selected directory.

But I got the following error, what is the problem?

Warning: Error in [: object of type 'closure' is not subsettable [No stack trace available]

Thanks a lot.

library(shiny)
library(shinyFiles)

ui <- shinyUI(bootstrapPage(
  shinyDirButton('folder', 'Folder select', 'Please select a folder', FALSE)
))
server <- shinyServer(function(input, output) {
  volumes = getVolumes()
  shinyDirChoose(input, 'folder', roots= volumes)
})

shinyApp(ui=ui, server=server)

Upvotes: 2

Views: 339

Answers (1)

stefan
stefan

Reputation: 124083

The famous error message "Object of type closure is not subsettable" indicates that you are trying to subset a function. In your case the issue is that getVolumes() returns a function which when called returns a vector of available volumes. To solve your issue change your call of shinyDirChoose like so:

server <- shinyServer(function(input, output) {
  volumes = getVolumes()
  shinyDirChoose(input, 'folder', roots = volumes())
})

Upvotes: 4

Related Questions