Skip to content
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

Gradio component tracking issue #6554

Open
jleibs opened this issue Jun 12, 2024 · 5 comments
Open

Gradio component tracking issue #6554

jleibs opened this issue Jun 12, 2024 · 5 comments
Labels
notebook Jupyter notebooks etc 🎄 tracking issue issue that tracks a bunch of subissues

Comments

@jleibs jleibs added 🎄 tracking issue issue that tracks a bunch of subissues notebook Jupyter notebooks etc labels Jun 12, 2024
@radames
Copy link

radames commented Jun 17, 2024

Hi @jleibs, I'm bringing this on here as well. radames/gradio-rerun-viewer#5
Can I get mount events via rr = new WebViewer() thus creating a loading bar on the custom component

@jprochazk
Copy link
Member

jprochazk commented Jun 17, 2024

TL;DR: No, and it's difficult to do properly

There are no such events exposed right now. The way rerun.io/viewer works is that it loads the JS and Wasm from a separate host which is determined dynamically from the path, e.g. rerun.io/viewer/version/nightly. It involves doing a fetch for the JS/Wasm, and it's possible to measure the progress (both current and total payload) of the Response.

The rerun-io/web-viewer package does not use the same approach. It is meant for bundling into applications, so it uses dynamic import, which is something that bundlers understand as "please put this part of the code in a separate bundle, and load it lazily".

The problem with that approach is that there's no way to track the progress of the import. I don't know of a bundler-agnostic way to say "please put this part of the code in a separate bundle, and _give me the URL to load it", so that we could use fetch and track the download progress.

Some bundlers support the new URL("./file.js", import.meta.url) pattern (https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url), and we can try using that, but I'm concerned about the portability.

@radames
Copy link

radames commented Jun 17, 2024

I see. I was thinking about trying onMount to do a dynamic import. At least you will have a simple signal that something is loading, though not necessarily the progress bar I was talking about.

loading = true
const viewer = await import("@rerun-io/web-viewer");

@jprochazk
Copy link
Member

jprochazk commented Jun 17, 2024

Yes, in that case it's already possible, by setting loading = true before calling WebViewer.start, and then setting loading = false when the promise resolves:

<script>
  import { WebViewer } from "@rerun-io/web-viewer";
  import { onMount } from "svelte";
  
  let rr;
  let loading = false;
  onMount(() => {
    rr = new WebViewer();

    loading = true;
    rr.start().then(() => loading = false);

    return () => rr.stop();
  }); 
</script>

Or with the new ready event in 0.17:

<script>
  import { WebViewer } from "@rerun-io/web-viewer";
  import { onMount } from "svelte";
  
  let rr;
  let loading = false;
  onMount(() => {
    rr = new WebViewer();

    loading = true;
    rr.on("ready", () => loading = false);
    
    rr.start();
    return () => rr.stop();
  }); 
</script>

@radames
Copy link

radames commented Jun 17, 2024

Perfect! that's enough IMO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notebook Jupyter notebooks etc 🎄 tracking issue issue that tracks a bunch of subissues
Projects
None yet
Development

No branches or pull requests

3 participants