简体   繁体   中英

R/Shiny: dirname not accepting reactive value

Trying to pass a reactive value into the dirname() function in R/Shiny. Getting error: Error in dirname: a character vector argument expected

I setup reactiveValues like this:

server <- function(input, output, session) {
    v = reactiveValues(root = '/path', files = NULL, folders = NULL)

I then have a button press observeEvent:

observeEvent(input$Btn, {
    v$files <<- grep("stuff", list.files(path = files.path(v$root), recursive=T, pattern=".py"))
    v$folders <<- dirname(v$files)
})

Why won't dirname accept the reactive value "v$files" as an argument? and how can I get it so it does accept it?

As mentioned by Aurèle, The missing value=T argument in the grep was causing the issue. Adding that gave me the intended result.

grep("stuff", list.files(path = files.path(v$root), recursive=T, pattern=".py"), invert=T, value=T)

Also pointed out by Aurèle, I switched the assignments to single arrow since double is not necessary when using reactive values it seems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM