Conditionally showing loading/spinner content while libraries are loading #7485
Unanswered
jimjam-slam
asked this question in
Q&A
Replies: 1 comment 3 replies
-
I'm also interested in extending this to error handling for things like data loading, although I think I'd just wrap a full JS async fetch block in a cell for that! |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Demos for this thread are in
jimjam-slam/demo-quarto-dynamic-imports
!I often use a conditional pattern to show a message instead of a plot:
test-good.qmd
If you select the fourth island option here, you get a message instead of the plot.
I'm interested in doing something similar to show a spinner or a message when cells haven't yet loaded. The motivating idea is that it's not uncommon to get errors in subsequent cells until library imports revolve. For example, here's a demo where we use two exports from Arquero,
aq
andop
. If you put on network throttling, you'll notice the errors complaining aboutop
until the library import is fully resolved:test-import-bad.qmd:
Here's a demo where we don't use Arquero, but we sleep for 5 seconds before showing anything. We
yield
undefined, then sleep, then yield the filtered value. Then we test for undefined when conditionally rendering our content:test-sleep.qmd:
Can we apply this idea to imports? Here we try to yield the default value and then immediately yield the filtered data using Arquero instead of a regular JS filter.
I was hoping we'd be able to detect the intermediate
undefined
value here due to Arquero loading (especially when network throttling is turned on), but it seems like nothing appears until it is fully loaded. And we still get the errors aroundop
:test-load-static.qmd:
Maybe dynamic imports can fix this! Here's a version where we dynamically import Arquero inside the data filtering cell. This seems to work: we get the expected
undefined
(so we can conditionally show a "loading" message), then the filtered data:test-load-dynamic-single.qmd
But I'm not sure how to make this work with multiple named exports. If we introduce a reference to
op
(as intest-load-dynamic-multiple
), we get our errors back (and in fact they never resolve).I've also tried rewriting the dynamic import line as
const {aq, op} = await import("https://cdn.jsdelivr.net/npm/arquero@5/dist/arquero.min.js")
, but no dice.Does anyone have a better solution for spinners and loading content, especially where multiple exports are concerned?
Beta Was this translation helpful? Give feedback.
All reactions