2017-07-28 76 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] 
相关问题