2

A year ago I was building a Shiny app and was asking how to display the default folder with shinyFiles.

At this time, with the help of commentators, I built a reproducible example, which was working:

library(shiny)
library(shinyFiles)

ui <- fluidPage( # Application title
  mainPanel(
    shinyDirButton("dir", "Input directory", "Upload"),
    verbatimTextOutput("dir", placeholder = TRUE)  
  ))

server <- function(input, output) {
  shinyDirChoose(
    input,
    'dir',
    roots = c(home = '~'),
    filetypes = c('', 'txt', 'bigWig', "tsv", "csv", "bw")
  )

  global <- reactiveValues(datapath = getwd())

  dir <- reactive(input$dir)

  output$dir <- renderText({
      global$datapath
  })

  observeEvent(ignoreNULL = TRUE,
               eventExpr = {
                 input$dir
               },
               handlerExpr = {
                 home <- normalizePath("~")
                 global$datapath <-
                   file.path(home, paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep))
               })
}

# Run the application
shinyApp(ui = ui, server = server)

Now it's time to update my Shiny app, I updated the R version and a number of packages and it stopped working. I'm getting the following error:

Warning: Error in $: $ operator is invalid for atomic vectors
  75: unlist
  72: observeEventHandler
   1: shiny::runApp

I can't figure out what is wrong now. I tried installing the previous version of shinyFiles but surprisingly still getting the same error. So it must be some other package.

I would appreciate any ideas!

UPD. Adding req(is.list(input$dir)) fixed the problem, now I can the file selection works in the app but if I run it from Docker, I can't see the shared directory...

kintany
  • 531
  • 1
  • 6
  • 15
  • The problem seems to be the `dir()$path[-1]`. I don't see any documentation for a `$path` property for the input object. Where did that come from? – MrFlick Nov 15 '18 at 20:45
  • I'm trying to find a reference now but I can't... Weird. – kintany Nov 15 '18 at 21:13

1 Answers1

2

Ok, just got a reply from shinyFiles developers: https://github.com/thomasp85/shinyFiles/issues/109#issuecomment-439185038

Inserting req(is.list(input$dir)) fixed the problem.

kintany
  • 531
  • 1
  • 6
  • 15