1

I tried to use the correct answer from Display selected folder path in Shiny but when I press "Input directory" button the whole app breaks down and gives me the following error:

Listening on http://127.0.0.1:7753
Warning: Error in $: $ operator is invalid for atomic vectors
  75: unlist
  72: observeEventHandler [C:\Users\makis\Documents\NVB/app.R#30]
   1: runApp

What may be the issue? Maybe happens only in my machine.

    library(shiny)
    library(shinyFiles)

    # Define UI for application that draws a histogram
    ui <- fluidPage( # Application title
      mainPanel(
        shinyDirButton("dir", "Input directory", "Upload"),
        verbatimTextOutput("dir", placeholder = TRUE)  # added a placeholder
      ))

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

      dir <- reactive(input$dir)
      output$dir <- renderText({  # use renderText instead of renderPrint
        parseDirPath(c(home = '~'), dir())
      })

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

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

I attach my sesssioninfo below. Note that since I have loaded other packages in this working directory more packages that those I seem to use here are displayed.

 sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.1.0      shinyFiles_0.7.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18    withr_2.1.2     crayon_1.3.4    digest_0.6.15   later_0.7.3     mime_0.5       
 [7] R6_2.2.2        xtable_1.8-2    jsonlite_1.5    git2r_0.23.0    magrittr_1.5    httr_1.3.1     
[13] rlang_0.2.1     curl_3.2        rstudioapi_0.7  promises_1.0.1  devtools_1.13.6 tools_3.4.1    
[19] httpuv_1.4.5    yaml_2.1.19     rsconnect_0.8.8 compiler_3.4.1  memoise_1.1.0   htmltools_0.3.6
> 
firmo23
  • 7,490
  • 2
  • 38
  • 114

2 Answers2

2

This question is answered on github: https://github.com/thomasp85/shinyFiles/issues/109

One needs to add the line: req(is.list(input$dir)) to your observeEvent:

observeEvent(ignoreNULL = TRUE,
               eventExpr = {
                 input$dir
               },
               handlerExpr = {
                 req(is.list(input$dir))
                 home <- normalizePath("~")
                 global$datapath <-
                   file.path(home, paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep))
               })
ross
  • 2,684
  • 2
  • 13
  • 22
Lisa B.
  • 235
  • 1
  • 11
  • When I run this I get this error: `Warning: Error in <-: object 'global' not found [No stack trace available]` – mikey Dec 10 '19 at 13:53
0

Worked with shinyFiles_0.6.2 and shiny_1.0.5

firmo23
  • 7,490
  • 2
  • 38
  • 114