【问题标题】:using Source() in Shiny在 Shiny 中使用 Source()
【发布时间】:2014-03-18 20:18:44
【问题描述】:

我有一个可用的 R 应用程序,我想使用 Shiny 在线提供。我的应用程序接收一个文件作为输入,因此客户端通过 ui.R 上传文件。 server.R 接收文件,然后我想调用我的应用程序。但是,当我使用 source() 时,myApp 不知道我在 server.R 中收到的文件并抛出 error : object not found。这是服务器的代码。R

shinyServer(function(input, output) {

   output$contents <- renderTable({
   inFile <- input$file1
   if (is.null(inFile))
      return(NULL)
   else{
      tdata <- as.matrix(read.table(inFile$datapath))
      head(tdata, n = 2)
      source("./CODE/run_myApp.r")
   }
  })
})

但是,myApp 不包含tdata(在我当前的应用程序中需要它作为输入文件)。

【问题讨论】:

  • 尝试使用source("./CODE/run_myApp.r", local = TRUE)
  • 这部分需要isolateisolate({source("./CODE/run_myApp.r")})
  • @jdharrison 谢谢,现在可以使用了
  • @Elahehkamaliha 您能否将下面 jdharrison 的答案标记为答案?

标签: r shiny


【解决方案1】:

要在闪亮的应用程序中使用源代码,您需要调用 local = TRUE 参数,因此在这种情况下:

shinyServer(function(input, output) {

   output$contents <- renderTable({
   inFile <- input$file1
   if (is.null(inFile))
      return(NULL)
   else{
      tdata <- as.matrix(   read.table(inFile$datapath))
      head(tdata, n = 2)
      source("./CODE/run_myApp.r", local = TRUE)
   }
  })
})

【讨论】:

    猜你喜欢
    • 2018-06-24
    • 2016-05-04
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多