您可以使用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=",")
})
})
})
)