R 执行ShinyFileChoose处理时,如何停止处理直到选择了文件

R 执行ShinyFileChoose处理时,如何停止处理直到选择了文件,r,shiny,R,Shiny,我们目前正在开发一款闪亮的应用程序。 使用ShinyFileChoose读取文件时,我希望将读取的文件存储在变量中,并将其连接到后续处理。 因此,我想在使用ShinyFileChoose选择文件时停止该过程。 我该怎么办 下面是示例代码 library ("shiny") library ("shinyWidgets") ui <-fluidPage ( shinyFilesButton ('file','Reading file ...','

我们目前正在开发一款闪亮的应用程序。 使用ShinyFileChoose读取文件时,我希望将读取的文件存储在变量中,并将其连接到后续处理。 因此,我想在使用ShinyFileChoose选择文件时停止该过程。 我该怎么办

下面是示例代码

library ("shiny")
library ("shinyWidgets")

ui <-fluidPage (
  shinyFilesButton ('file','Reading file ...','choose file', FALSE),
      textOutput ("OUTPUT_TEXT")
)

server <-function (input, output, session) {
  
  observeEvent (input $ file, {
    
    volumes <-c ("Documents" = Sys.getenv ("HOME"))
    shinyFileChoose (input,'file', session = session, roots = volumes, filetypes = c ('','txt'))
    
    unlistfile <-unlist (input $ file)
    filename <-c (unlistfile [2] [1])
    
    output $ OUTPUT_TEXT <-renderText ({
      paste0 (volumes, "\\", filename)
    })
  })
}

shinyApp (ui = ui, server = server)
库(“闪亮”)
图书馆(“shinyWidgets”)
ui您可以尝试:

library(shiny)
library(shinyWidgets)
library(shinyFiles)

ui <-fluidPage (
  shinyFilesButton ('file','Reading file ...','choose file', FALSE),
  tableOutput("OUTPUT_TABLE")
)

server <-function (input, output, session) {
  
  observeEvent (input$file, {
    volumes <- c("Documents" = Sys.getenv ("HOME"))
    shinyFileChoose (input,'file', session = session, roots = volumes, filetypes = c ('','txt'))
    if(length(input$file) <= 1) return({})
    output$OUTPUT_TABLE <- renderTable ({
      df <- read.csv(input$file$files[[1]][[3]])
      df
    })
  })
}

shinyApp (ui = ui, server = server)
库(闪亮)
图书馆(shinyWidgets)
图书馆(shinyFiles)

谢谢你的评论。 但是发生了一个错误 「错误在[[:]抱歉,你的评论似乎不完整。我在我的系统上的两个文件上测试了这个,它没有任何错误。明白。这是版本问题吗?关闭这个一次没有问题。