-
Notifications
You must be signed in to change notification settings - Fork 39
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
allow multiple values in query strings #73
Conversation
dash_labs/plugins/pages.py
Outdated
try: | ||
first = json.loads(first) | ||
v = json.loads(v) |
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.
What's the use case for json loading the value here? And in particular, do we need to json.loads
each item, if we have a list at this point?
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.
@chriddyp can you answer this question about the use-case for json.loads?
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.
JSON parsing - to bring number strings into numbers and allow human readable booleans (true
, false
)
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.
Sorry, @chriddyp I don't understand your answer - could you elaborate?
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.
Example: ?weekends=false&start=5
. If we don't JSON parse, then the dev would get literally the strings 'false'
and '5'
. By JSON parsing, the dev will get False
(a Python boolean) and 5
(a number)
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.
@alexcjohnson should we also use this with the path variables for consistency?
If so, should the default path when using a path_template
be "/dasboard/null"
rather than "/dashboard/none"
?
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.
"False", "True" and "None" remain as strings.
Oh true, good point. That feels a bit confusing, I could imagine that we convert those to the Python types as well
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.
After giving this a little more thought, I think it might be better to keep data as strings. For example, not all string numbers should be converted to int or float. What if the number was part of a 3 digit string id? "?id=010"
would be converted as a string {"id": "010"}
but "?id=100"
would be converted as an int {"id": 100}
.
Plus there are other keywords that would convert that people might not expect -- such as "NaN" and "Infinity"
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, I'm starting to think the same - with all the questions about JS vs Python keywords, and now @AnnMarieW's point about numeric strings that aren't numbers, automatically converting just seems too ambiguous and confusing.
For path variables we could adopt Flask's convention of <converter:name>
, but unless we can think of a good place to specify similar converters for query parameters I'm leaning toward leaving them as strings.
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.
@chriddyp Is this good to go now? I removed the json.loads.
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.
💃🏼
Yippee - Thanks! |
This pull request allows for multiple values in query strings to be passed to the layout function.
For example, this URL has 2 values for
indi
:The following is now passed to the layout function. Note that the value for
indi
is a listPreviously, only the first value was included: