【问题标题】:roots argument in shinyFileChoose() is not reactive to inputshinyFileChoose() 中的根参数对输入没有反应
【发布时间】:2020-03-08 08:02:07
【问题描述】:

我正在尝试在我的一个应用程序中使用 shinyFileChoose(),问题是,我需要让用户搜索的顶级目录相当大,并且有数千个子目录,从而降低了应用程序的速度。

一个明显的(对我来说)解决方案是获取 2 级子目录的列表,让用户简单地在 selectInput() 中选择一个子目录,然后将此子目录作为 shinyFileChoose() 的根。使用您机器的主目录的可重现示例如下:

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)

然后我遇到的问题是,仅第一次将根设置为反应卷()。也就是说,当第一次单击 shinyFilesButton ("chooseFiles") 时,根被正确设置为 2 级子目录指向的任何一个;但是,如果我更改了在 selectInput() 中选择的值,再次单击 shinyFilesButton,则根没有更新。

如果这种行为是预期的,或者我错过了什么,请告知。非常感谢!

> 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   

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    你可以这样做:

      shinyFiles::shinyFileChoose(input = input, "chooseFile", 
                                  roots = exprToFunction(c(chosenFolder = volumes())), 
                                  session = session)
    

    【讨论】:

      猜你喜欢
      • 2017-01-30
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 2023-03-10
      • 2016-10-11
      • 2023-01-25
      • 2021-12-04
      • 1970-01-01
      相关资源
      最近更新 更多