Skip to content
Advertisement

How to consolidate action buttons for individual objects into a single selectInput() in R shiny?

The code posted below allows the user via clicks of action buttons to add/delete individual rhandsontable tables for data input. For deletion each table has its own action button underneath. Any ideas how to consolidate those delete action buttons into a single selectInput() where all tables are listed for deletion? I’ve tried un-nesting the deletion function observeEvent(input[[btnID]]...) which triggers a removeUI(), for quite a while now, but I have completely hit a brick wall.

Code:

JavaScript

Advertisement

Answer

You could collect the user’s deletion choices as a reactive value in the server part:

JavaScript

… add a select input to your UI (I chose a selectize input)

JavaScript

and update this value in your event observer for input$addTbl:

JavaScript

(note that a reactiveVal is set with an argument rather than via assignment operator: my_reactive_val(x) instead of my_reactive_val <- x)

edit Please see working version below. I added a “Delete” button: when triggering delete on selection change, tables would be removed until none are left.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement