Skip to content
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

Merged
merged 5 commits into from
Jan 25, 2023
Merged

Conversation

wch
Copy link
Collaborator

@wch wch commented Jan 23, 2023

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:

@wch wch requested a review from schloerke January 23, 2023 19:53
@jcheng5
Copy link
Member

jcheng5 commented Jan 23, 2023

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.

@wch
Copy link
Collaborator Author

wch commented Jan 23, 2023

Just curious - what did you need insertion order for?

@rpodcast
Copy link

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.

@wch
Copy link
Collaborator Author

wch commented Jan 24, 2023

@jcheng5 I'll update this PR to return keys in insertion order.

@wch wch requested a review from jcheng5 January 24, 2023 20:46
values$B <- 12
# Setting an existing value shouldn't change order
values$a <- 1
values$A <- 11
Copy link
Member

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.

Copy link
Collaborator Author

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.

@wch wch merged commit 38337a9 into main Jan 25, 2023
@wch wch deleted the reactivevalues-order branch January 25, 2023 17:10
@github-actions github-actions bot restored the reactivevalues-order branch January 25, 2023 17:17
@wch wch deleted the reactivevalues-order branch January 25, 2023 17:17
schloerke added a commit to rstudio/shinycoreci that referenced this pull request Feb 15, 2023
@daattali
Copy link
Contributor

daattali commented Aug 14, 2023

I've run into this issue many times as well, I'll see if my 4 year old issue can be closed #2629

@daattali
Copy link
Contributor

Yep, I love when you guys fix old issues I've been waiting on for years 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants