How can I obtain just the selected directory name from a ShinyFiles
directory button? I looked at this post, another SO question, and got it to show the full path in a verbatimTextOutput
, but I just want the directory name. I tried printing out to console like message()
and print()
. It has some weird integers getting printed at the same time. I tried isolate(reactiveValuesToList(base_name))
, dir()$path[[2]]
but I"m not successful.
1
[1] 1
attr(,"class")
[1] "integer" "shinyActionButtonValue"
list("", "flowCyt_pdfs")home
$path
$path[[1]]
[1] ""
$path[[2]]
[1] "flowCyt_pdfs"
$root
[1] "home"
Warning: Error in $: $ operator is invalid for atomic vectors
library(shiny)
library(shinyFiles)
ui <- fluidPage(
navbarPage(
tabPanel("test",
sidebarPanel(
tags$h2("HEADER"),
shinyDirButton("dir", "Input Directory", "")
),
mainPanel(
h4("DIRPATH OUTPUT"),
verbatimTextOutput("dirpath_dply")
)
)
)
)
server <- function(input, output) {
home_dir <- "/home/dir/path"
shinyDirChoose(
input,
"dir",
roots = c(home = home_dir),
filetypes = c('', "txt", "png", "pdf")
)
dir <- reactive(input$dir)
output$dirpath_dply <- renderText({
parseDirPath(c(home=home_dir), dir())
})
observeEvent(ignoreNULL = TRUE,
eventExpr = {
input$dir
},
handlerExpr = {
base_name <- unlist(dir())
message(base_name)
datapath <- file.path(home_dir,paste(unlist(dir()) ))
})
}
shinyApp(ui, server)