Open gver84 opened 4 months ago
I think your situation could work with two changes:
Step 1: Install the development version of the package. Using remotes:
remotes::install_github("thomasp85/shinyFiles")
If you want to install the specific commit at the time of writing, it's
remotes::install_github("thomasp85/shinyFiles@da361359712bbcd74dd6a9505a88ec87aead13bc")
The patch in the development version of the branch was actually written on 5th July 2023 but hasn't been released yet. It's frustrating, because I also need the same patch for my work.
Step 2: Modify a line of your app code (removing brackets after roots
):
observe({ shinyDirChoose(input, "dir1", roots = roots) })
This leaves you with the following app code:
library(shiny)
library(shinyFiles)
library(fs)
ui <- fluidPage(
titlePanel("Add Volume to Roots in Shiny"),
shinyDirButton("dir1", "Select Directory 1", "Please select a directory"),
verbatimTextOutput("roots_info")
)
server <- function(input, output, session) {
# Initial roots definition
roots <- reactiveVal(c(
home = fs::path_home(),
output = paste0(fs::path_home(), "/Eclipse")
))
# Show the current roots information
output$roots_info <- renderPrint({ roots() })
# Initialize shinyDirChoose for the directories
observe({ shinyDirChoose(input, "dir1", roots = roots) })
# # Handle the directory selection
observeEvent(input$dir1, {
dir1 <- parseDirPath(roots(), input$dir1)
if (!is.null(dir1) && !anyNA(dir1) && length(dir1) > 0) {
new_roots <- roots()
new_roots["custom"] <- dir1
roots(new_roots)
}
})
}
shinyApp(ui, server)