2014-10-30 28 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=",")    
    }) 
}) 
}) 
) 
相關問題