-
Notifications
You must be signed in to change notification settings - Fork 151
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
[Feat] Add Figure
model and introduce KPI card functions
#493
Conversation
for more information, see https://pre-commit.ci
…izro into feat/create_kpi_cards
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.
Magnificent work! The "Figure" is something that opens up a lot of new possibilities 🚀.
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.
🚀 😍 Really love this new feature! I think it is definitely a good addition.
Provided a few comments, but nothing crucial. For the name, I wanna ponder a little more, but I think I have no better idea 😂
One more random thought: are we sure about having the My feeling is that we probably do want them: I am actually quite happy with supporting this API e.g. as compared to custom charts, where the whole alignment (or lack thereof) with the Just thought I'd raise this as a discussion point, as when we have hosted examples very soon, there might be a little less need for things to be native. Another big pro here is of course that we can then configure KPI cards via |
I feel strongly about including the KPI cards in our public API, more than any of the custom charts we plan to bring from our internal library. Apart from your arguments, it's worth adding because it's such a widespread component used in any business dashboard. Since customizing the At some point, we discussed whether we should only have one KPI card function and combine the two here. But there were a few reasons why we decided not to do that. First, we wanted to avoid exposing someone who wants a simple KPI card to an API with all these extra arguments that are also not intuitive. Hence, all of these long docstrings 😄 The other point is the concept of Any customizations of the current KPI cards (e.g., layout changes, including subtitles or any of that sort) should live in the docs. I think the current implementations can cover 80% of what people might want to do, as any customization can be done quickly based on the existing implementations. What we did not include are KPI cards with sparklines or KPI groups that flexibly rearrange themselves based on screen width/height. For me, this can all live in docs. However, the code that can cover 80% of all KPI Cards should be added by us 👍 |
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.
Had another pass - good stuff!
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 was reading the docstrings to get some context before reviewing the docs and just left a few other small comments too. Really nice work on the PR description here, it's super clear and useful 🙏
- "{value:.0%}": Formats the value as a percentage without decimal places. | ||
- "{value:,}": Formats the value with comma as a thousands separator. | ||
|
||
agg_func: String function name to be used for aggregating the data. Common options include |
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.
This is a great point @maxschulz-COL and I basically agree with both of you. It's actually pretty hard/impossible to find a definitive list of what strings work here in pandas - I've also wondered about this meany times before. It's nowhere in the official docs, and the system is basically yes, you just guess function names, and probably it will work 😆 The best reference I've found is this: https://stackoverflow.com/questions/65877567/passing-function-names-as-strings-to-pandas-groupby-aggregrate. So I would keep the text as is but add "For more information on possible functions, see https://stackoverflow.com/questions/65877567/passing-function-names-as-strings-to-pandas-groupby-aggregrate".
FYI it is deliberate that we only demonstrate how to do this with strings and keep the type-hint as str
for exactly the reason @huong-li-nguyen says, so that things work in yaml straight away also. But I have deliberately chosen to not add in some validation that throws an exception if a callable is provided instead, because there's no reason to forbid that from working in Python and it would just make things more complicated than needed given these are meant to be simple copy and pastable functions.
Description
Why introduce the
Figure
model?This PR was initially intended to enable reactive Cards as we needed them for the KPI Cards. Still, several iterations and prototypes clarified that a higher-level model was required to allow any dash component to be reactive.
We've been hesitant to introduce this model as we first wanted to see if it is needed, so we started with lower-level models such as Table, Graph, AgGrid, and Card as they are also more declarative. However, in the future, we could subclass the
Table
,Graph
, andAgGrid
from theFigure
, see Antony's comment here: #493 (review)As you already see, the naming is not optimal, which was also one of the reasons why we didn't go with it straight away 😄 So if you strongly disagree with
Figure
as a name, please raise your opinion here, such that we can find a name that everyone can accept more or less: #493 (comment)I'll split docs in a separate PR as this model needs proper documentation and probably lots of explanation, as its purpose is unclear from the naming alone. @stichbury I would probably need your help on that 👍
What does this
Figure
solve for?Essentially, it will enable any dash component to be reactive to controls (not filter interactions, as this logic needs to live in any subclass implementation for now). This could have already been useful and a better approach when:
Table
,Graph
,AgGrid
and doesn't qualify for another sub-category (can't think of any right now anyways)How did we get here from the KPI Card?
Ultimately, the KPI Cards are just implementations of CapturedCallables that go into
Figure
.However, before we got here, I considered four different approaches and did prototypes for all of them.
1) Use a custom chart with go.Indicator and provide to vm.Graph ❌
2) Use a custom component ❌
3) Extend the vm.Card model with a figure attribute ❌
text
andhref
. While it was possible, there were several drawbacks to this approach:- Because the text and nav card were now provided as CapturedCallable, they started loading as well, which just wasn't nice UX as these components are static
- The build, in the end, was not connected to the Card, and any intention to do that meant having to move the
dbc.Card
outer container from the CapturedCallable, which led to several issues given classNames needing to be provided- Given that the build was not connected to the Card anymore but could have been the higher-level model for any dash component that we might want to be reactive to controls, approach 4 made more sense ⬇️
4) Create a new component with a figure attribute ✅
What will be our default KPI Cards?
I've created designs for 3 KPI Cards and aligned with @Joseph-Perkins that these will be the ones we want to offer by default. Users can still create their own KPI Cards by providing their own CapturedCallable. Colors, etc., might still change, but the overall structure remains the same:
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":