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
from_dict() method to fully set st.query_params, similar to experimental_set_query_params #8407
Comments
@Asaurus1 @sfc-gh-bhay @sfc-gh-bhess @marcotielen WDYT? Thoughts or other ideas on the method name? I think cc @willhuang1997 @vdonato @LukasMasuch in case you have thoughts. Otherwise I'd be happy for someone to contribute this 😃 |
I like set_all, as an aptly describes what you're doing which is setting all of the query params. It's just unfortunate that you named the operation to get a specific key as a list value "get_all" because I also agree that the fact it's not symmetrical is a bit grating 🫠. Perhaps "set_entire" or "set_every" could work. I don't particularly like set_dict: if dict is meant to describe the thing you're passing in, I don't think it belongs in the name and we wouldn't want to restrict the input to a dictionary, it could be any mapping that supports keys and get item. Likewise, if it's meant to describe the thing that query params are, that's also a bit misleading because even though they're stored internally in a dictionary, they're not exactly the same thing. I think "set_params" would be preferable even though the word "params" would be doubled up on. "Set" while short might conflict with existing keys so I think we should avoid it. |
You could also do "from_dict" which would at least mirror well with "to_dict"... "from_mapping" might be technically more correct but eh... I could live with it. |
Here's a draft PR for review, once we agree on a name can add things like tests + type proxy functions + all that fun stuff. |
I vote from_dict . Nicely in line with pandas. The only unfortunate part is that to_dict has a different behavior for lists (repeating keys). But who knows what the future can bring on that one. |
Yeah this is a good point. To_dict and from_dict won't be perfect mirrors due to certain design decisions that were made. I.e. |
I can live with that… the intent is there. But I’m the newbie here 🙂 |
@sfc-gh-jcarroll I think |
One other idea would be |
Imo that would be way too easy to accidentally pass. You could call |
@Asaurus1 , @sfc-gh-bhay , @sfc-gh-jcarroll , @sfc-gh-wihuang , @willhuang1997 , @LukasMasuch : vote? not sure how to create a poll, but the below will do. Vote with an emoticon. st.query_params.set_dict() > thumbs up |
Well all right well unless the other three are going to all vote for the same one we seem to have a clear choice here, I will be AFK for the next few days. Will or Joshua or marcotielien feel free to take the code from my branch above and run with it. |
I'm on windows and not a regular streamlit dev. So I just took the nightly build and adjusted below two files (streamlit\runtime\state). query_params.txt test code (easy to verify through checking browser history):
|
Let's go with |
Ready for review. @marcotielen I tested your code above with this version and I think it's working as expected. |
@Asaurus1 I did notice that both .update and .from_dict don’t have telemetry. Is that needed? |
## Describe your changes Implements an atomic way to overwrite all query_params ## GitHub Issue Link (if applicable) Closes #8407 ## Testing Plan Unit tests for query_params and query_params_proxy. --------- Co-authored-by: Vincent Donato <vincent@streamlit.io>
Checklist
Summary
Provide a single method on
st.query_params
which takes a dict input and does the following as a single operation: removes any existing keys and sets the query params to match the input dict.Why?
We have seen some advanced apps that manage multiple query params and want to set them simultaneously, and/or set some query_params and remove all others based on some user action.
In this case, the new
st.query_params
current functionality is actually worse than what was possible withst.experimental_set_query_params
, as two updates are needed:It would be nice to do this as one operation, especially since it has consequences on the browser history.
How?
The API should have basically the same behavior as experimental_set_query_params, except taking a single dict argument instead of arbitrary kwargs that are converted to a dict. It should be a method on
st.query_params
instead of a standalone function.After discussion we agreed on:
st.query_params.from_dict()
✅Additional Context
See discussion in
The text was updated successfully, but these errors were encountered: