S.Br
S.Br

Reputation: 33

Is there a way in R shiny to concatenate all values taken by an input

My question is very basic.

INPUT : any key on the keyboard (input$mydata)
SERVER : register all changes occuring in input$data (for instance in a vector) DESIRED OUTPUT: the vector of all values taken by input$mydata
(and maybe the vector is reset when there are for instance 50 values registered)

I try many way, even global values but nothing is working...

Here is the code for displaying the last key input

library(shiny)
runApp( list(ui = bootstrapPage(
  verbatimTextOutput("results"),
  verbatimTextOutput("allInputs"),
  tags$script('
              $(document).on("keypress", function (e) {
              Shiny.onInputChange("mydata", e.which);
              });
              ') 
  )
  , server = function(input, output, session) {

    output$results = renderPrint({
      input$mydata
    })
  }
))

Upvotes: 1

Views: 252

Answers (1)

ismirsehregal
ismirsehregal

Reputation: 33530

You can append the changes to a reactiveVal:

library(shiny)
runApp( list(ui = bootstrapPage(
  verbatimTextOutput("results"),
  verbatimTextOutput("allInputs"),
  tags$script('
              $(document).on("keypress", function (e) {
              Shiny.onInputChange("mydata", e.which);
              });
              ') 
)
, server = function(input, output, session) {

  output$results = renderPrint({
    input$mydata
  })

  keysPressed <- reactiveVal()

  observeEvent(input$mydata, {
    keysPressed(c(keysPressed(), input$mydata))
  })

  output$allInputs = renderPrint({
    keysPressed()
  })

}
))

Upvotes: 2

Related Questions