I would like to remove an actionButton once it has been clicked. I had previously used shinyjs::hide("init")
successfully, but now I would like to remove the button altogether. I have tried the following code
The issue stems from modularization. It updates a vector GlobClass$Init
based on a unique ID userPID
. The non-modularized of the code version works.
Example.R
library(shiny)
### Modularized Code
#' UserSide Function to Create Button
InitializeUI <- compiler::cmpfun( function(id) {
ns <- NS(id)
actionButton( ns("init"), h4("Initialize") )
})
#' ServerSide Function to Update reactive Vector and Delete Button
Initialize <- compiler::cmpfun( function(input, output, session,
GlobClass, userPID ) {
observeEvent( input$init, {
cat("click\n")
removeUI(selector='#init', immediate=TRUE)
GlobClass$Init[userPID] <- TRUE
}, autoDestroy=TRUE)
})
### User.R
ui <- fluidPage( InitializeUI("init") )
### Server.R
GlobClass <- reactiveValues(Init=c(FALSE, FALSE))
server <- function(input,output) {
userPID <- sample( 1:2,1)
cat(userPID, "\n")
callModule( Initialize, "init", GlobClass, userPID )
}
### Run Application
shinyApp(ui, server)