-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that reactiveValues
keys and values are sorted
#3774
Conversation
I'm OK with this (and definitely better than random order!) but it's a slight shame that they're not in insertion order, like a named list. @rpodcast and I needed this the other day and ended up resorting to tracking the insertion order in a side list. |
6068407
to
a3424c0
Compare
Just curious - what did you need insertion order for? |
@jcheng5 and I have been working on improving my workflow of dynamic UI insertions into a Shiny app based on some real life examples. The goal is to have a custom R6 class to manage a lot of the details for an improved user experience over my existing methods. In some of my applications, the order of how these dynamic UIs are entered actually matters as they can represent sequential parameter sets that need to follow the order of insertion. I realize that's not a very common use case of dynamic UI, but for my purposes it can be very helpful. |
@jcheng5 I'll update this PR to return keys in insertion order. |
values$B <- 12 | ||
# Setting an existing value shouldn't change order | ||
values$a <- 1 | ||
values$A <- 11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we don't have the notion of removing a value? That's the only other case I could think of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we don't have a way to remove a value.
I've run into this issue many times as well, I'll see if my 4 year old issue can be closed #2629 |
Yep, I love when you guys fix old issues I've been waiting on for years 🥳 |
This PR also ensures that anywhere that a
reactiveValues
$names()
or$values()
method is called, the keys will be sorted in the same order that they were inserted. (Note: a previous version of this PR sorted lexicographically, and some of the comments were for that version.)In our shinycoreci tests, we found that bookmarked input values were not always in consistent order. For example, for the same app in the same state, both of these URLs might be generated: