使用rstudioapi :: selectDirectory从终端错误运行应用

时间:2019-08-22 09:59:19

标签: shiny

我想从终端启动一个闪亮的应用程序。我的应用程序有一个按钮,当按下该按钮时,会打开一个窗口以选择具有功能 rstudioapi :: selectDirectory()

的文件夹

但是当我单击按钮时,出现此错误:

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

app.R

library(shiny)

# 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()
    print(path.file)
  })

}

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

在终端上

$ "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 http://127.0.0.1:6283
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

1 个答案:

答案 0 :(得分:0)

您正在运行一个Shiny进程,而不是RStudio。