R 活性成分的来源

R 活性成分的来源,r,shiny,R,Shiny,我想将我的应用程序拆分为更小的Peace,以便更好地处理 server.R library(shiny) source("onLoad.R", local = TRUE) shinyServer(function(input, output, session) { sourceRecursive("/.../") }) output$myChoices <- renderUI({ selectInput(inputId = 'x',

我想将我的应用程序拆分为更小的Peace,以便更好地处理

server.R

library(shiny)
source("onLoad.R", local = TRUE)

  shinyServer(function(input, output, session) {

     sourceRecursive("/.../")

 })
output$myChoices <- renderUI({
    selectInput(inputId = 'x', 
            label = 'y', 
            choices = levels(myDataSet$df$z),
            multiple = T
    )
})
sourceRecursive

#check folder and all subfolders for .R files
#source() them! 
sourceRecursive <- function(path) {
      dirs <- list.dirs()
      files <- dir(pattern = "^.*[Rr]$", include.dirs = FALSE)
      for (f in files)
          source(f)
      for (d in dirs)
          sourceRecursive(d)
 }
#检查文件夹和所有子文件夹中的.R文件
#来源()他们!

sourceRecursive如果在对源代码的调用中使用
local=TRUE
,如果
sourceRecursive
在正确的范围内(可能将其放在server.R中),该怎么办。请参阅此文档

如果在调用源代码时使用
local=TRUE
,前提是
sourceRecursive
在正确的范围内(可能将其放在server.R中)。请参阅此文档

我正在使用source(local=TRUE)和sys.source将文件加载到适当的环境中,它似乎可以工作:

library(shiny)
shinyServer(function(input, output, session) {
    # From http://shiny.rstudio.com/articles/scoping.html
    output$text <- renderText({
        source('each_call.R', local=TRUE)
    })

    # Source in the file.R from the example in the question
    sys.source('file.R', envir=environment())
})
库(闪亮)
shinyServer(功能(输入、输出、会话){
#从http://shiny.rstudio.com/articles/scoping.html
output$text我正在使用source(local=TRUE)和sys.source将文件加载到适当的环境中,它似乎可以工作:

library(shiny)
shinyServer(function(input, output, session) {
    # From http://shiny.rstudio.com/articles/scoping.html
    output$text <- renderText({
        source('each_call.R', local=TRUE)
    })

    # Source in the file.R from the example in the question
    sys.source('file.R', envir=environment())
})
库(闪亮)
shinyServer(功能(输入、输出、会话){
#从http://shiny.rstudio.com/articles/scoping.html

输出$text没有答案,但是你可以有
x没有答案,但是你可以有
x