remove button after n clicks

Hello,
I would like to have an actionButton disapearing after a given number of clicks.

In the following example, the actionButton disapear after one click, but I would like to set as a variable the number of times I have to click before removing the button

Have no idea actually...

library(shiny)

ui <- fluidPage(
  actionButton('init','Click')
)

# The server function
server <- function(input,output) 
{
  observeEvent(input$init, {
    removeUI(selector='#init', immediate=TRUE)
  }, autoDestroy=TRUE)

}

shinyApp(ui, server)

Hello,
I would like to remove the action button after 3 clicks on it, but it doesn't work...

library(shiny)

ui <- fluidPage(
  actionButton('init','Click')
)

# The server function
server <- function(input,output) 
{
  observeEvent(input$init==3, {
    removeUI(selector='#init', immediate=TRUE)
  }, autoDestroy=TRUE)

}

shinyApp(ui, server)

It works for ONE click if I remove the condition "==3", but this is not what I'm trying to achieve...
Cheers,
C.

Have you tried putting the test inside the observeEvent function?

library(shiny)

ui <- fluidPage(
  actionButton('init','Click')
)

# The server function
server <- function(input,output) 
{
  observeEvent(input$init, {
    if (input$init == 3)  removeUI(selector='#init', immediate=TRUE)
  }, autoDestroy=TRUE)

}

shinyApp(ui, server)


1 Like

Hi,
great! It works! Thanks a lot!

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