-
Notifications
You must be signed in to change notification settings - Fork 261
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: mo.lazy #1052
feat: mo.lazy #1052
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 nice! I like the thorough docs, too (I pushed up some small docs changes).
I left one comment about the argument name show_spinner
. Additionally, playing with the smoke test, I found that lazy components in an accordion sometimes don't render. See video for example - it only renders at the very end.
lazy-spinner-bad-interaction.webm
marimo/_plugins/stateless/lazy.py
Outdated
def __init__( | ||
self, | ||
element: Union[Callable[[], object], object], | ||
show_spinner: bool = 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.
Thoughts on changing this argument name to show_loading_indicator
, to make it agnostic to the UI?
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.3.9-dev10 |
* feat: mo.ui.lazy * doc touch up docstrings * docstring fix * add performance guide to docs index * set min h * show-loading-indicator * fix lint --------- Co-authored-by: Akshay Agrawal <akshay@marimo.io>
This PR adds a new component
mo.lazy
to lazily render FE or lazily compute BE (python)For example,
In this example,
mo.ui.table(data)
will not be rendered on the frontend until is it in the viewport.For example, an element can be out of the viewport due to scroll, inside a tab that is not selected, or inside an accordion that is not open.
However, in this example, data is eagerly computed, while only the rendering of the table is lazy. It is possible to lazily compute the data as well: see the next example.
In this example, we pass a function to
mo.lazy
instead of a component. This function will only be called when the user opens the accordion. In this way,expensive_component
lazily computed and we only query the database when the user needs to see the data. This can be useful when the data is expensive to compute and the user may not need to see it immediately.