manu p
manu p

Reputation: 985

Capture input ID of the action button

I have a shiny application with action button

actionButton("show",class = "act_button", list(span(class="top left", "Model 1"), span(class="top right", Sys.time())))

Now, the ID of this action button is "show" Is there a way to capture this ID when this button is clicked. Like

  observeEvent(input$show,{
    print(input$show)
  })

Actual ouput

[1] 1
attr(,"class")
[1] "integer"                "shinyActionButtonValue"

Expected output

show

Upvotes: 0

Views: 451

Answers (1)

Pork Chop
Pork Chop

Reputation: 29387

You can pass the name with this.textContent and id with this.id

library(shiny)

ui <- fluidPage(
  actionButton("show", "show", onclick = "Shiny.onInputChange('myclick', this.id)")
)

server <- function(input, output, session){
  observeEvent(input$show,{
    print(input$myclick)
  })
}

shinyApp(ui, server)

enter image description here

Upvotes: 1

Related Questions