我想將我的應用程序拆分成更小的和平以獲得更好的處理。無源內容中的來源Shiny
server.R
library(shiny)
source("onLoad.R", local = TRUE)
shinyServer(function(input, output, session) {
sourceRecursive("/.../")
})
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)
}
示例文件我嘗試源。 file.R
output$myChoices <- renderUI({
selectInput(inputId = 'x',
label = 'y',
choices = levels(myDataSet$df$z),
multiple = T
)
})
反彈有:在輸出$ myChoices
錯誤< - renderUI({: 對象 '輸出' 未找到
顯然的問題是,在file.R
變量output
未定義,因爲這是一個變量,在閃亮的上下文中使用。我怎麼會告訴R
(或閃亮)將所有變量視爲閃亮定義的變量(如output$whatever
,input$something
,reactive
等)。這對我來說很重要,爲了把這個計劃分解成更小的和平。
沒有你的答案,但你可以在你的file.R中有'x < - renderUI({...})',然後使用在服務器中輸出$ mychoices < - x' – Chris