Dynamically add elements with ActionButton in a Shiny app

I'm trying to write an app where one can throw a coin several times, so every time the ActionButton is pressed a new element is added to a vector. This vector then I would like to use to display the results in a plot.
My problem is that vector. I don't yet have lots of experience with Shiny, so I don't know if there's a specific function for that as I didn't find anything since now.

Can someone give me a hint of how that would be possible?
Thanks in advance!

you want to add a value to a vector ? Thats the c() concatenation function

(v1 <- 1:3)
#1 2 3
(v2 <- c(v1, 4))
#1 2 3 4

Yes, I know that function. But it didn't work in Shiny. I always got the Error "Error in: evaluation nested too deeply: infinite recursion / options (expressions =)?"
I think the problem is that I want to do that in a Shiny App. So I would need a vector where a value is added every time the person is pressing the ActionButton.


ui <- fluidPage(
  actionButton("b1", "press"),

server <- function(input, output, session) {
  hist_vec <- reactiveVal(NULL)

  observeEvent(input$b1, {
      sample(c("H", "T"), 1)

  output$t1 <- renderTable({
    r <- req(hist_vec())

shinyApp(ui, server)

Thank you very much!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.