The bottom code is supposed to allow the user to select a file from their directory and save their selection in directory_path but for some reason, it doesn't work.
Thanks in advance for the help!
library(shiny)
library(shinyFiles)
ui <- fluidPage(
shinyDirButton("directory", "Select Directory", "Please select a directory"),
verbatimTextOutput("selected_directory")
)
server <- function(input, output, session) {
# Initialize reactive values object to satore selected directory
rv <- reactiveValues(directory_path = NULL)
# Create reactive value for selected directory
selected_directory <- eventReactive(input$directory, {
chosen_dir <- shinyDirChoose(input, "directory", roots = c(home = '~'), filetypes = NULL)
if (!is.null(chosen_dir)) {
return(as.character(chosen_dir$value))
}
})
# Update selected directory in reactive values object
observe({
rv$directory_path <- selected_directory()
})
# Display selected directory in output
output$selected_directory <- renderText({
paste0("You selected the following path: ", rv$directory_path)
})
}
shinyApp(ui = ui, server = server)