I have a pair of auxiliary inputs that allows user to choose combinations from a set of choices. Also, it is convenient one to be able to remove an item that was created before.
Answer from Joe Cheng at Shiny Google Groups:
Yeah, you can't replace an entire reactiveValues instance like that and expect anything that's bound to the previous reactiveValues instance to instantly know about the new one. The slots on the reactiveValues instance itself are reactive, but its own variable is not.
I think the real issue here is that, unlike lists and envs, you can't remove values from reactiveValues, only set them to NULL.
There are two easy workarounds I can think of:
1) In addition to the
reactiveValues
instance's slots being reactive, also make the variable reactive, using makeReactiveBinding.2) You could also use reactiveValues as normal, but keep a list IN the reactiveValues that holds the combinations, not having the reactiveValues itself hold the values. In other words,
values <- reactiveValues(combos = list())
, and when something new gets added,values$combos[[x]] <- y
.In trying out fix number 1 above, I found that updateSelectInput doesn't work properly when choices is a length-0 vector. Instead of sending a 0-length vector to the client, it doesn't send anything for choices at all, so the choices never change.
I've forked your gist and added two revisions: one that implements workaround #1 (along with some other problems I found), and one that works around the updateSelectInput issue by using renderUI. https://gist.github.com/jcheng5/eaedfed5095d37217fca/revisions