2017-07-28 45 views
1

當在RShiny中製作更大的應用程序時,我喜歡將我的代碼保存在單獨的文件中以獲得單獨的選項卡或菜單。當我將RShiny命令放入.R文件並使用source()命令調用它時,會在UI元素下面打印一個TRUE。我曾嘗試在ui.RuiOutput()以及invisible()中使用呼叫源。在沒有TRUE評估的情況下使用Rshiny中的源代碼

如何停止TRUE呈現?

例子:

app.R

library(shiny) 

ui <- fluidPage(h4("Attempt 1"), 
       source("TestSource.R",local=T), 
       h4("Attempt 2"), 
       uiOutput("at2"), 
       h4("Attempt 3"), 
       invisible(source("TestSource.R"))) 

server <- function(input, output) { 
    output$at2 <- renderUI({ 
    invisible(source(
     "TestSource.R", 
     verbose = F, 
     echo = F, 
     print.eval = F, 
     prompt.echo = F, 
     local = T 
    )) 
    }) 
} 

shinyApp(ui = ui, server = server) 

TestSource.R

helpText("This is a test") 

以下是這使它

An example output

在此先感謝。

+0

你試過'無形(源(「TestSource.R」))'? –

+0

是的,這也行不通。 –

+0

'{source(「TestSource.R」); NULL}'? –

回答

2

使用source("TestSource.R", local=TRUE)$value

一個很好的解釋是here

+0

謝謝,我很驚訝我沒有在我的搜索中發現這個問題! –

+1

有時候會發生,實際上我的答案是書籤。我們仍然需要人類。 – Geovany

0

源函數產生一個列表:

List of 2 
$ value :List of 3 
    ..$ name : chr "span" 
    ..$ attribs :List of 1 
    .. ..$ class: chr "help-block" 
    ..$ children:List of 1 
    .. ..$ : chr "This is a test" 
    ..- attr(*, "class")= chr "shiny.tag" 
$ visible: logi TRUE 

所以你可以嘗試:

source("TestSource.r")[1] 
相關問題