2015-09-30 28 views
1

我想在我的閃亮應用程序(http://code.tutsplus.com/tutorials/3-key-software-principles-you-must-understand--net-25161)中堅持KISS(保持簡單,愚蠢)的原則。從子文件夾實現R-Files到Shiny

所以我創建了一個文件夾和子文件夾和保存的一塊塊我的代碼使用在server.R進入功能和.R文件。 這裏兩個兩個例子保存.R文件:

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

absoluteMatrix <- reactive({ 
    lifeChar <- switch(as.integer(input$something), 
        "abc", 
        "def", 
        "ghi", 
        "jkl", 
        "mno" 
    ) 

    if((myBoolean$absolute == TRUE) && (length(input$xy) != 0)){ 

     if((length(input$gh) == 0)) { 
      return(myData()[,grepl(lifeChar, names(myData()))] %>% 
         na.omit %>% 
         as.matrix) 

     } else if((length(input$gh) != 0)) { 
      return(myDataX()[,grepl(lifeChar, names(myDataX()))] %>% 
         na.omit %>% 
         as.matrix) 
     } 
    } 
}) 

server.R我寫了下面

library(shiny) 
source("onLoad.R") 

    shinyServer(function(input, output, session) { 

    sourceRecursive("/.../") 

}) 

onLoad.R文件中的函數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) 
    } 

但是,這並沒有辦法。它似乎沒有加載文件,或者它們的內容可能存在問題reactivity

+2

你可以試試給你的source()函數添加'local = TRUE'嗎? –

+0

我想在這裏你可以找到一個很好的解釋如何使用閃亮的應用程序使用多個文件。 http://stackoverflow.com/questions/30534674/displaying-true-when-shiny-files-are-split-into-different-folders/30538596#30538596 – Geovany

+0

@BogdanRau做了詭計!謝謝:) – Stophface

回答

0

向source()函數添加'local = TRUE'。

相關問題