Shiny - 如何将渲染函数分离到不同的文件中?

Shiny - How to separate the Rendering functions into different files?

如何将 Rendering functions 分成不同的文件?

例如,

我的 server.R,

里有这个
shinyServer(function(input, output, session) {

   output$text <- renderUI({...})

   output$annotations <- renderDataTable({...})

   output$plot <- renderPlot({...})

}))

我可以将 output$textoutput$annotationsoutput$plot 放入 单独的文件 中,然后再导入它们吗?

我的尝试,

source('source/server/getRenderUI.R', local = TRUE)
output$text <- getRenderUI()

结果,

Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

我认为你不需要打电话给 getRenderUI(),你可以试试这个

In getRenderUI.R

  output$text <- renderUI({...})

In server.R 

  shinyServer(function(input, output, session) {

    source('...../getRenderUI.R', local = TRUE)$value

 }))

对我来说,这很管用。

注意:注意output$xxx不要重名,因为所有变量都在同一个作用域