Skip check on whether a component is passed as a non-children property.#1916
Skip check on whether a component is passed as a non-children property.#1916emilhe wants to merge 1 commit intoplotly:devfrom
Conversation
|
@emilhe really interesting solution with A big caveat with this method is that the dash renderer doesn't know that these components exist, so they can't be used in callbacks as either inputs or outputs - we get that info by crawling the layout looking for IDs, but we only descend into It's also a little worrisome that On the other hand, So I'd love to see if we can find a way to accomplish this, but keep the cool ability to selectively render but do it off the dash-renderer codebase, and maintain the ability to link these components to callbacks. |
|
@alexjohnson yes, I have looked through (some of) the discussions. The performance considerations mentioned there was one of the main reasons I decided to work on an solution via external library rather than pursuing a PR. I am (painfully) aware of the callback limitation. I actually have a lot of use cases where this limitation is a show stopper, but I figured that with an external library this was probably 'the best that could be done' (to enable callbacks, I guess the solution would have to be implemented inside the dash renderer, right?). And even without callbacks, I think this solution is a significant step forward as compared to not being able to pass components at all. I actually started writing my own very simple render code, which worked in terms of rendering, but it emitted some weird React warnings. After trying to debug it without success, I decided to mimic the behavior of the dash renderer more closely. As a result, the warnings disappeared, but the code is now vastly more complex and contains lot's of code duplicated from the dash renderer. I guess the proper solution here would be to separate out the render functionality in a separate (plotly owned) npm package, which can then be used both by the dash renderer and dash-extensions-js (or the custom component authors directly). I believe that making the rendering optional for the developer at the prop level is the key to avoid performance issues. We could even provide two options; render a prop with callbacks enabled, or render it without callbacks enabled for improved performance. I believe that would yield the best of both worlds. How do you think the best possible solution would look in terms of syntax? Would it be that the dash renderer just renders all props with BTW: This discussion is going way beyond the original intent of the PR :) |
|
following |
|
Closing this PR: the first part of this (simple props other than The second part, conditionally rendering deeply-nested Dash components, we'll address soon, but not in the next release. @emilhe really appreciate your work here, I expect the eventual built-in solution will closely follow your lead. |
Officially, Dash only supports passing other Dash components via the
childrenprop. And for that reason (I guess), a check is being performed in the Python layer (inbase_component.py) to catch if people try to do it,However, it is possible to render components passed via non-children properties - in fact I have developed some JS code (available in dash-extensions-js) that makes it possible to do it in a single line of code. This option dramatiacally improves the development experience and the flexibility of the resulting Dash components allowing stuff like,
This code already works with the current version of dash, but only because the list wrapping of the
Iconifycomponent cheats the check listed above. Hence the following code will not work with the current version of Dash,since the check will be hit. In this PR, I am proposing to remove the check so that the above code will work too.
The main limitation of this approach is that components rendered this way are now known by the dash renderer, so they cannot be targeted by callbacks.