jupyterlab/jupyterlab-hdf5

Extending the default file browser to launch an HDF5 rendering extension

JonjonHays opened this issue · 8 comments

We're developing an extension that renders a visualization of data stored in HDF5 files. Our original intentions were to extend the default file browser's "Open With" menu; however, after a chat with @telamonian and @saulshanabrook, it turns out this may not be trivial for our particular use case. @saulshanabrook mentioned that the canonical way to extend the "Open With" menu would be to create a Mime Renderer extension, but a Mime Renderer extension wants to load the file into local memory by default. This is a problem for us, as we are dealing with remote files much too large to pull into local memory, and our extension only needs the small portion of the file that is actually being rendered. So, we're looking for the simplest way to launch the extension via the browser, while only retrieving the target filename in the process, rather than the file data. Extending the "Open With" menu, the file browser's menu itself, or something involving the data registry are all acceptable for us, we're just trying to avoid something super clunky like entering the filename in a text field. Thanks so much for all the help!

Tagging @shreddd here as well.

Max just opened a PR to support adding a mime render that doesn't get any contents, so you can just use the path: jupyterlab/jupyterlab#7596

Awesome! I'll stay tuned.

Ok took a look through the PR. @telamonian @saulshanabrook would you say it's safe to go ahead and start implementing our extension as a Mime Renderer, and change any fileFormat params to null after this has been merged, or should we maybe hold off for a bit? I.e, is it pretty certain that @telamonian 's PR will fix this issue? @shreddd

As an aside, does anyone know how I can get the file path from within a Mime Renderer extension? I was assuming it would be in IMimeModel.metadata, but I've been playing with the cookie cutter Mime Renderer and the metadata object has nothing but a fragment property. I've also looked at the IRenderer and IRendererOptions interfaces, but I'm not seeing a path property or a method for retrieving one anywhere. At some point the doc manager makes a request with the file path in the request URL, but I'm not seeing where this is actually passed to the extension. Thanks for any tips!

I still struggle to figure out how to get access to the filepath from "IRenderMime.IMimeModel", there is no context in this, and I don't see how to get access to the docregistry for the selected file...

sorry for hi-jacking this thread, but I really have the same issue on getting access to the path of the file. Here in the ViewerWidget based on IRenderer I tried adding the DocRegistry but the context is never passed to the functions when I run the code, I only get the model.data in the consol.log at least...

export class MyViewerWidget extends Widget implements IRenderMime.IRenderer {
  /**
   * Construct a new output widget.
   */
  constructor(options: IRenderMime.IRendererOptions, context?: DocumentRegistry.IContext<DocumentRegistry.IModel>) {
    super();
    this._mimeType = options.mimeType;
    if (context) {
      this._context = context;
    }
    this.addClass(CLASS_NAME);
    this._iframe = document.createElement('iframe');
    this.node.appendChild(this._iframe);
    this._iframe.width = "100%";
    this._iframe.height = "100%";
  }

  renderModel(model: IRenderMime.IMimeModel): Promise<void> {
    console.log(model.data);
    const path = this._context?.path;
    if (path) {
      console.log('path:',path)
    }
    const lpath = this._context?.localPath;
    if (lpath) {
      console.log('lpath:',lpath)
    }
    return Promise.resolve();
  }

  private _iframe: HTMLIFrameElement;
  private _context?: DocumentRegistry.IContext<DocumentRegistry.IModel>;
  private _mimeType: string;
}

Closing this as it is not really related to the jupyterlab-hdf extension.

https://discourse.jupyter.org/ may be an excellent place to continue the discussion !