I am trying to create a UI matrix of action buttons that increase in value by one when clicked (Counter with a different value for each button through ObserveEvent). I would like to have access to those values in R after closing my shiny app in the form of a matrix, for sport scouting purposes. So far what I did was, to create a separate variable for each button, and to copy paste the same counter function again and again. But obviously this results in ugly code and long waits when launching, even though it works. I would like to shorten my code by creating a loop in the server part, maybe by doing a matrix of those "storage" values and making the loop add one to the values when the related action button is activated in the UI. I included my code below, please be kind, I'm no programmer and have little experience! Thank you.
a_OH1_z1_q1 <- 0
ui <- fluidPage(
navbarPage(
"Scouting",
id = "navtab",
tabPanel("Attack",
navlistPanel(
tabPanel('OH1',
mainPanel(
tags$b("______1____________2____________3_____________4______"),
br(),
actionButton("aOH1z1q1", a_OH1_z1_q1,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z1q2", a_OH1_z1_q2,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z1q3", a_OH1_z1_q3,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z1q4", a_OH1_z1_q4,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
br(),
actionButton("aOH1z2q1", a_OH1_z2_q1,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z2q2", a_OH1_z2_q2,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z2q3", a_OH1_z2_q3,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z2q4", a_OH1_z2_q4,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
br(),
actionButton("aOH1z3q1", a_OH1_z3_q1,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z3q2", a_OH1_z3_q2,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z3q3", a_OH1_z3_q3,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z3q4", a_OH1_z3_q4,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
br(),
actionButton("aOH1z4q1", a_OH1_z4_q1,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z4q2", a_OH1_z4_q2,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z4q3", a_OH1_z4_q3,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z4q4", a_OH1_z4_q4,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
br(),
actionButton("aOH1z5q1", a_OH1_z5_q1,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z5q2", a_OH1_z5_q2,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z5q3", a_OH1_z5_q3,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z5q4", a_OH1_z5_q4,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
br(),
actionButton("aOH1z6q1", a_OH1_z6_q1,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z6q2", a_OH1_z6_q2,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z6q3", a_OH1_z6_q3,
style = "width: 100px; height:100px; background-color:blue; color:white;"),
actionButton("aOH1z6q4", a_OH1_z6_q4,
style = "width: 100px; height:100px; background-color:blue; color:white;")
)
)
)
)
)
)
server <- function(input, output, session) {
observeEvent(
input$aOH1z1q1,{
a_OH1_z1_q1 <<- a_OH1_z1_q1 + 1
updateActionButton(session,"aOH1z1q1",label = a_OH1_z1_q1)
}
)
}
shinyApp(ui,server)