rstudioapi::selectDirectory - run app from terminal

I want to launch a shiny application from a terminal. My application has a button that when pressed opens a window to select a folder with the function rstudioapi::selectDirectory()

But when i click on the button i get this error:

$ "Rscript.exe" -e "shiny::runApp('Shiny/app.R')"
Loading required package: shiny
Warning: package 'shiny' was built under R version 3.5.3

Listening on
Warning: Error in : RStudio not running
  76: stop
  75: verifyAvailable
  74: callFun
  73: rstudioapi::selectDirectory
  72: observeEventHandler [D:/Users/folder/Shiny/app.R#12]
   1: shiny::runApp

# Define UI for application that draws a histogram
ui <- fluidPage(

  actionButton("folder", "Choose folder")


server <- function(input, output) {
  observeEvent(input$folder, {
    path.file <- rstudioapi::selectDirectory()


# Run the application
shinyApp(ui = ui, server = server)

The problem is that rstudioapi::selectDirectory() requires that RStudio is running, and it's not. You'll need to use some other technique instead.

ha ok :frowning: . I found this alternative shinyFiles


ui <- fluidPage(
    shinyDirButton(id="folder", label="folder", title="folder", 
                   buttonType = "default", 
                   class = NULL, icon = NULL, style = NULL),
server <- function(input, output,session) {
  volumes <- c(Home = fs::path_home(), "R Installation" = R.home(), getVolumes()())
  shinyDirChoose(input, "folder", roots = volumes, 
                 session = session, 
                 restrictions = system.file(package = "base"))
  output$directorypath <- renderPrint({
    parseDirPath(volumes, input$folder)
shinyApp(ui, server)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.