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.
library(shiny)
ui <- fluidPage(
actionButton("b1", "press"),
tableOutput("t1")
)
server <- function(input, output, session) {
hist_vec <- reactiveVal(NULL)
observeEvent(input$b1, {
hist_vec(c(
hist_vec(),
sample(c("H", "T"), 1)
))
})
output$t1 <- renderTable({
r <- req(hist_vec())
as.data.frame(table(r))
})
}
shinyApp(ui, server)