当您需要在现有输出中附加值时,如何在Shiny中处理它?
简化我的问题:
我想在单个变量中创建逗号分隔的代码列表,即:
02,04,05,11,31
并在创建时显示列表。我按照我的方式验证代码,这不是问题。
我目前有一个文本输入小部件来输入我的代码。 每次按动作按钮时,我都希望在文本输入字段中附加值。
有没有如何做到这一点的例子?
当我尝试使用输出对象并向其添加内容时,Shiny不喜欢它。
答案 0 :(得分: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=",")
})
})
})
)