-
Notifications
You must be signed in to change notification settings - Fork 949
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
Expose URL transformation logic for JLab #2800
Comments
We've thought about exposing some sort of url transformation function from the widget manager, which should be responsible for all environment-specific aspects of the widget. In the jupyterlab widget manager, it would tap into the system url transformation. For the notebook, it would likely be the (default) identity transform. This has also come up when displaying html in ipywidgets vs using the default jupyterlab html display. JupyterLab automatically converts local links to work in JupyterLab, but the html widget can't. Providing some sort of url transformation mechanism would allow the html widget to be able to do a similar transformation. |
To be more specific, what I think would be good to try is:
|
As a hacky kludgy workaround for now, if a widget is being hosted by a jupyterlab widget manager, it can access the |
Thanks @jasongrout , it looks like I'm doing it the kludge way today 🙈 If anyone is wondering how to access/use the import { DOMWidgetView } from '@jupyter-widgets/base'
export class YourWidget extends DOMWidgetView {
async getDownloadUrlFor(fsPath) {
const resolver = this.model.widget_manager.rendermime.resolver
// First we resolve fsPath in case its relative
const resolvedPath = await resolver.resolveUrl(fsPath)
// We return a a 'http://{labinstance}/files/___' URL
return await resolver.getDownloadUrl(resolvedPath)
}
} |
I was looking into it, but don't we have it already? ipywidgets/jupyterlab_widgets/src/manager.ts Lines 614 to 620 in cb8eefe
|
Huh, that looks right! Can you use git blame (or the blame view in GitHub) to track down the pr that added that for reference? |
Thanks! |
Actually, it looks like what is still needed is moving that functionality up to the base manager, so any widget can use it without knowing if it is in JLab, etc. |
I thought it was how it's working already: because this functionality is in the |
@davidbrochart / @jasongrout if this is already fixed, its probably "too hard to find" haha, and perhaps a couple lines of code for future people running into the issue might actually weirdly be a high impact documentation fix. I'll note that in general, I love how awesome a lot of the jupyterlab ecosystem github issues are in terms of completeness BUT, I find SO many issues closed where a one liner by whoever fixed it in the issue showing how to USE the fix would save every developer trying to understand the issue like...... hours |
That is: people find issues when figuring out how to do things, please please please note HOW the fix works when closing issues, it takes the fixer 5 minutes to save everyone else feeling stupid for 3 hrs reading patches and trying to figure out WHAT the fix is |
This method is already exposed on the widget manager interface. Here in the master branch: ipywidgets/packages/base/src/manager.ts Lines 187 to 192 in 8a8d804
And on the 7.x branch (since 7.2 it looks like), the base manager class also defines it: ipywidgets/packages/base/src/manager-base.ts Lines 478 to 485 in 1326c9b
To use it in a widget method, you can call: let resolvedUrl = this.widget_manager.resolveUrl("./smiley.jpg"); |
Hello, I am the author of a custom ipywidget. I recently added in functionality that passes a relative image URL from Python -> JS, and display that image in the widget view.
Let's say I have Classic Notebook Server running. I have a notebook open at
/some/path/example.ipynb
, and I have an image/some/path/smiley.jpg
. I pass the relative image path of"./smiley.jpg"
from Python -> JS, and the image is able to display correctly in an HTML element there.This same workflow fails in JupyterLab, because of how JupyterLab is structured and how it assembles URLs. Here is an example of how JupyterLab changes the
./smiley.jpg
URL tohttp://localhost:8889/files/some/path/smiley.jpg?_xsrf=<somerandomstring>
It would be great if this functionality was exposed from an
ipywidget
perspective, so there was a unified programming interface for Classic Notebook Server and JupyterLab. For now, a workaround I will do I will probably implement separate logic for notebooks and jupyterlab, using jupyterlab services and the contentsmanager API.cc @timkpaine and @jasongrout , we discussed this on gitter
The text was updated successfully, but these errors were encountered: