2014-10-30 29 views
0

如何在Shiny中处理它,当您需要将值附加到已经存在的输出时?使用Shiny创建一个以逗号分隔的字符串列表

为了简化我的问题:

我想创建一个逗号单一变量,即分离代码列表:

02,04,05,11,31

,并显示列表作为我去创造它。我随时验证代码,这不是问题。

我目前有一个文本输入小部件来输入我的代码。 我想每次按动作按钮时将文本输入字段中的值追加到列表中。

是否有任何如何做到这一点的例子?

闪亮不喜欢它,当我尝试使用输出对象并追加一些东西给它。

回答

0

您可以使用Paste来做到这一点。我确定有很多其他的方法可以做到这一点,在这里看看这个例子reactivePoll and reactiveFileReader在画廊部分。以下是一个示例代码,我只需打印出Sys.time()并将其附加到最后一个条目。

下面是两个例子:

实施例1无按钮

library(shiny) 
runApp(list(ui = fluidRow(wellPanel(verbatimTextOutput("my_text"))), 

server = function(input, output, session) { 
    autoInvalidate <- reactiveTimer(1000,session) 
    my_file <- as.character(Sys.time()) 
    output$my_text <- renderText({ 
     autoInvalidate() 
     my_file <<- paste(my_file,as.character(Sys.time()), sep=",") 
    }) 
    }) 
) 

实施例2与ActionButton

library(shiny) 
runApp(list(ui = fluidRow(actionButton("push","Append"),wellPanel(verbatimTextOutput("my_text"))), 

server = function(input, output, session) { 

my_file <- as.character(Sys.time()) 
output$my_text <- renderText({ 

if(input$push==0) 
{ 
return(my_file) 
} 
isolate({ 
input$push 
my_file <<- paste(my_file,as.character(Sys.time()), sep=",")    
    }) 
}) 
}) 
) 
相关问题