【问题标题】:Using Shiny to create a comma delimited string list使用 Shiny 创建逗号分隔的字符串列表
【发布时间】:2014-10-31 02:04:37
【问题描述】:

当您需要将值附加到已经存在的输出时,您如何在 Shiny 中处理它?

为了简化我的问题:

我想在单个变量中创建一个逗号分隔的代码列表,即:

02,04,05,11,31

并在创建列表时显示该列表。我在进行时验证代码,这不是问题。

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

有没有例子说明如何做到这一点?

Shiny 不喜欢我尝试使用输出对象并向其附加一些内容。

【问题讨论】:

    标签: shiny


    【解决方案1】:

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

    带有 ActionButton 的示例 2

    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=",")              
      })
     })
    })
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多