user3463225 user3463225 - 1 year ago 97
R Question

R shiny - last clicked button id

I have multiple action buttons, on which i want to show different select Inputs and I want to know last clicked button id, how can I do that? When I use

which(lapply(c(1:10), function(i) { input[[paste0("ActionButton", i)]]}) == TRUE)

It shows me all button which were clicked, however I want to know which one was the last in order to enable click once again on previous buttons. How can I do that? I am new in shiny and not sure if understand all reactive/isolate issue so I would be greateful for any hints.

Answer Source

You can do it by adding JS

smthing like

$(document).on('click', '.needed', function () {

Example ( add class needed to btn if you want to control not all btn)

 ui <- shinyUI(fluidPage(

  titlePanel("Track last clicked Action button"),
  tags$head(tags$script(HTML("$(document).on('click', '.needed', function () {

      actionButton("first", "First",class="needed"),
      actionButton("second", "Second",class="needed"),
      actionButton("third", "Third",class="needed"),
      actionButton("save", "save"),

    # Show a plot of the generated distribution


server <- shinyServer(function(input, output,session) {
    updateSelectInput(session,"which_",selected = input$last_btn)

# Run the application 
shinyApp(ui = ui, server = server)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download