-
Notifications
You must be signed in to change notification settings - Fork 144
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
Custom DateTimePicker component #901
Comments
Hey @gtauzin 👋 , nice to meet you? At the risk of not having understood your question, but isn't this the solution: https://vizro.readthedocs.io/en/stable/pages/API-reference/models/#vizro.models.DatePicker Let me know if you were looking for something else 💪 ! Best, Max |
Hi @maxschulz-COL and nice to meet you too! vizro's DatePicker only allows to pick date and not time. I need to pick both of them. dash-maintine-components has a DateTimePicker but only in its most recent version (>= 0.15.0) which is incompatible with vizro (requires <0.13.0 see here). That lead me to create my own by putting together two existing components of dash-mantine-components, DatePicker (on which vizro's DatePicker relies) and TimeInput. |
Ah I see, in that case I think @antonymilne has a potential solution for you :) |
Thanks @maxschulz-COL, that would be great! |
Hello @gtauzin and thanks for raising the issue. This is all very interesting. And thanks for the pycafe example that really helps understand what's going on. For a start, the dmc date picker components have caused us various problems and workarounds (as you can see by the comments), and about 6 months ago when we fixed stuff well enough we pinned to dmc<0.13.0 because we knew that future breaking changes were likely in dmc. I didn't know that 0.15 had now come out, which is good to know. I see that 0.12 still seems quite popular (more so than 0.14 in fact): https://pepy.tech/projects/dash-mantine-components?versions=0.14.*&versions=0.13.*&versions=0.12. In general, much as I love dmc, we are reducing our dependence on it (in favour of dbc) and I suspect the datepicker will be the only dmc component we have left soon. All this to say: we should try and bump our dmc dependency, but it's not a high priority I'm afraid. Possibly it would help with some of the date picker issues though @petar-qb? Which would offer some more incentives to make the change. I've made a ticket to try and see how easy it is to bump anyway: #905. When we do bump our dependency it remains to be seen if and how we would be able to build So I think for now the best approach is indeed to try and make your own custom component with Now onto your question: if I understand correctly, you'd like the default value shown by the date and time picker to correspond to today's date and the current time, is that right? I think something like this should be possible, although I suspect it might be a bit buggy or you might need to sacrifice something like persistence of value when you change pages. Are you using dynamic data? |
Hi @antonymilne. Thank you, I really appreciate the time you took to give me a better picture of the situation. I do not mind building a custom DateTimePicker as it is also a good way to improve my understanding of vizro. I do use dynamic data (through the kedro data catalog) but I am not sure how it is relevant to this custom component. In any case, let me try and explain more clearly the issue I am facing. When I create a Now, I wish to use the Thank you and please let me know if this is not clear! |
Ahhh ok, this makes sense I think. Having two selectors in one like you were trying was a good idea but I think might be harder to get working than having two separate selectors: one for a date and one for a time. At the moment we have a pretty hard assumption that each control can only pass a single Take a look at the below example on pycafe. It uses a custom figure just as a proof of concept to show how it works. There's a few gotchas with this:
|
Thank you so much for your help @antonymilne !
Indeed, points 1 and 4 (along with the additional complexity) were the reason why I tried to combine Thank you again :) |
The PR has merged and we've just done a release, so an improved rendering is now possible with With this release it's now possible to nest controls inside another model inside
Alternatively you might like to just make a whole new model for this which nests the parameters:
The |
On point 1 ("since they're separate components, whenever you change either date or time, the targeted components will update. This might be good or bad depending on your application"), I am curious actually, since after thinking about it some more I would guess that the behaviour of separate components here was actually what most people wanted. Just to understand, why is this instant update not the right behaviour for your app? Indeed once we bump dmc it should be easy to make a custom |
Congratulations on the release 🎉, it seems to be a really neat improvement! I really like the fact that vizro enables this kind of structured compositions. I'll try it out :)
Interesting. It is very similar to the composite DateTimePicker I had written in my first post (see PyCafe) and I indeed had to play a bit with CSS. I am curious: is there any difference with mine in terms of usability? |
At the moment, my app fetches data from the cloud based on date and time picked. Updating them separately means that if only one is properly set you fetch the wrong data. Note that in practice, my situation is worse as I have a start date/time and an end date/time. There is a simple workaround which is to add a button "Fetch data" and have the user click it once both date and time are set, but I initially thought this could be avoided.
So being able to make a custom DateTimePicker is easy but integrating a DateTimePicker into vizro is hard. I naively thought this would be the same. Thank you so much for your help. I love what you guys are doing with vizro, this really helps me having much cleaner app code. |
Yeah, I was actually very impressed with your CSS because these dmc components in particular are not so easy to handle in vizro, so you did a great job of it! There are basically two key differences compared to your version:
Thanks for explaining, this makes sense! Actually I'm not sure that the combined DateTimePicker in dmc 0.15 would be able to achieve this for you - if you look at the first example in their docs then after clicking the tick initially, it seems to update instantly even when you change just the date or time without clicking the tick again. Not sure whether that's intentional or not, but I don't see any options to change it to "wait until tick is clicked to apply change". So yes, for now you will indeed have to have a "Fetch data" button that's manually pressed I'm afraid. Possibly in future we could add some kind of functionality that allows you to have an "apply" button attached to a control group, and none of the controls in that group will trigger until manually applied. But that will not happen for a long time I think.
Thanks for your comments, that's much appreciated! 🙏 |
One more thought I just had on "wait until applying changes": you might be able to use
For 0.12 it says:
I don't know whether the change in docs are actually new functionality or if it's just improved docs. |
Thank you, this is very clear and makes a lot of sense!
Ah! That's a very good point. That was some wishful thinking on my side as I did not know about
This is clear, thank you so much for your help on this. |
Question
Hello,
I am trying to create a custom DateTimePicker component. Although dmc has one, it is available in v0.15 of dmc which is not available (yet?) in vizro. Can I first ask if anyone is aware of an open source version of such a vizro component? Seems like it should be pretty commonly used but could not find anything.
My idea was to take a DatePicker and a TimeInput both from dmc and put them next to each other in a group. However, I am running into the following issue:
value
, which is adatetime.datetime
. At build time, I passvalue.date()
to DatePicker andvalue.time()
to TimeInput. However, when it is modified, I would like to recomputevalue
from thedate_picker.value
and thetime_input.value
. Is it possible?Thank you for your help!
Code/Examples
This is what I came up with so far on PyCafe.
Which package?
vizro
Code of Conduct
The text was updated successfully, but these errors were encountered: