我尝试使用Display selected folder path in Shiny中的正确答案,但是当我按下“输入目录”按钮时,整个应用程序崩溃了,并给我以下错误:
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
可能是什么问题?也许只发生在我的机器上。
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)
我在下面附上我的sesssioninfo。请注意,由于我已经在该工作目录中加载了其他软件包,因此会显示更多我似乎在此处使用的软件包。
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
>
答案 0 :(得分:1)
此问题在github上得到了解答:https://github.com/thomasp85/shinyFiles/issues/109
需要将以下行添加到req(is.list(input$dir))
:
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))
})
答案 1 :(得分:0)
使用了ShinyFiles_0.6.2和Shiny_1.0.5