Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

roots argument in shinyFileChoose() is not reactive to input

$
0
0

I'm trying to use shinyFileChoose() in one of my applications, the problem is, the top-level directory where I need to let users search is fairly large and has thousands of subdirectories, thus slowing down the app.

One obvious (to me) solution is to get a list of the 2-level subdirectories, let user select a subdirectory simply in a selectInput(), then feed this subdirectory as the root for shinyFileChoose(). Reproducible example using your machine's home directory below:

library(shiny)
library(shinyFiles)

allinhome <- list.files("~")

ui <- fluidPage(
  selectInput("2LevelFolder", 
              "Select a folder in home directory.",
              choices = allinhome),

  shinyFiles::shinyFilesButton("chooseFile", 
                               "Explore and choose file", 
                               "This is the title",
                               multiple = TRUE),

  verbatimTextOutput("path")

)

server <- function(input, output, session) {

  volumes <- reactive(paste0("~/", input$`2LevelFolder`))
  shinyFiles::shinyFileChoose(input = input, "chooseFile", 
                              roots = c(chosenFolder = volumes()), 
                              session = session)


  output$path <- renderPrint({
    input$chooseFile
  })
}

shinyApp(ui, server)

The problem I then ran into is, the roots is set to the the reactive volumes() only the 1st time. That is, when the shinyFilesButton ("chooseFiles") was clicked for the 1st time, the root was set correctly to whichever the 2-level subdirectory points to; however, if I changed the value selected in selectInput(), click the shinyFilesButton again, the root was not updated.

Please advise if this behavior is expected or if I've missed something. Thanks you very much!

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] shinyFiles_0.7.3 shiny_1.3.2     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2      crayon_1.3.4    digest_0.6.20   later_0.8.0     mime_0.7        R6_2.4.0        xtable_1.8-4   
 [8] jsonlite_1.6    magrittr_1.5    pillar_1.4.2    rlang_0.4.0     rstudioapi_0.10 fs_1.3.1        promises_1.0.1 
[15] tools_3.6.1     httpuv_1.5.2    compiler_3.6.1  pkgconfig_2.0.2 htmltools_0.3.6 tibble_2.1.3   

Viewing all articles
Browse latest Browse all 201867

Trending Articles