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

[WIP] Prototype of streamlined Graphical GIS <-> Notebook "bounce" workflow #340

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mfisher87
Copy link
Member

@mfisher87 mfisher87 commented Jan 16, 2025

Description

Just barely got started implementing a streamlined version of the "GIS<->Notebook bounce" workflow with huge thanks to @martinRenou for making some time to teach me stuff this morning! I wanted to share our progress so far.

From an example notebook, we want to debug this geodataframe:

city_gdf.to_file("new_haven.json")
from jupytergis_lab.notebook.geo_debug import geo_debug

geo_debug("new_haven.json")

This opens a side panel with JupyterGIS displaying the data on a basemap. Eventually, I want to directly pass the geodataframe instead.

Still TODO, and I don't have time today:

  • Display the JupyterGIS toolbar in the widget; working on this now
  • Add a video demo to this PR
  • All the other TODOs in the changeset ;)

Checklist

  • PR has a descriptive title and content.
  • PR description contains references to any issues the PR resolves, e.g. Resolves #XXX.
  • PR has one of the labels: documentation, bug, enhancement, feature, maintenance
  • Checks are passing.
    Failing lint checks can be resolved with:
    • pre-commit run --all-files
    • jlpm run lint

📚 Documentation preview: https://jupytergis--340.org.readthedocs.build/en/340/
💡 JupyterLite preview is available from the doc, by clicking on lite badge

@mfisher87 mfisher87 added the enhancement New feature or request label Jan 16, 2025
Copy link
Contributor

Binder 👈 Launch a Binder on branch mfisher87/jupytergis/sidecar-experiment

Copy link
Contributor

github-actions bot commented Jan 16, 2025

Integration tests report: appsharing.space

@mfisher87 mfisher87 changed the title Prototype of streamlined Graphical GIS <-> Notebook "bounce" workflow [WIP] Prototype of streamlined Graphical GIS <-> Notebook "bounce" workflow Jan 16, 2025
this._jgisWidget = new JupyterGISPanel(options);
this._jgisWidget = new JupyterGISWidget({
// FIXME: Where do we get a context object?
// context: ...,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invoking help from @brichet 🙏🏽

Since JupyterGISWidget is a DocumentWidget, it's needs a context here.

Is JupyterGISWidget a good choice here?

The place I see where JupyterLab creates a document context is here https://github.com/jupyterlab/jupyterlab/blob/main/packages/docmanager/src/manager.ts#L549 I'm not sure we'd have everything in place to do something equivalent here. And should we?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can have a map with the toolbar without going through this.

Copy link
Collaborator

@brichet brichet Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that both solutions should be possible (create a context or add a toolbar to the widget), but I haven't test it.
The buttons on the toolbars looks for the active widget in the tracker, that mean that the created widget must be added to the tracker to make it work. Currently the tracker expect JupyterGISWidget, but it can be updated to allow also JupyterGISPanel I guess (or an other widget including JupyterGISPanel with a toolbar).

IIUC, this PR creates a temporary project file, and the goal is to open that file in a widget with a toolbar (the widget must be tracked). I think we'll have to activate the sidebars too, to be able to manage that map.
If this is true, I don't understand why we shouldn't open the regular JupyterGISWidget while splitting the main area. We'll get it all for free...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we shouldn't open the regular JupyterGISWidget while splitting the main area. We got all this working for free...

We can definitely take this approach 👍🏽

The jupyterlab-sidecar approach from Python was to get something on the screen quickly. I had a feeling that wouldn't be the long term approach we would take.

We can definitely have that Python function trigger opening the file next to the Notebook and splitting the main area.

Copy link
Collaborator

@brichet brichet Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to take that approach, we could probably use the command to open the file:

return app.commands.execute('docmanager:open', {
path: model.path,
factory: FACTORY
});

with an additional argument like to split the main area. I haven't tried it, but it should be something like:

app.commands.execute('docmanager:open', { 
  path: 'debug.jgis', 
  factory: 'JupyterGIS .jgis Viewer', // the factory name should be exported
  options: { mode: 'split-right' }
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's probably better to not depend on ipylab in a project like JupyterGIS.

ipylab is indeed still a bit more like a toy. It's likely fine if individual users install it themselves if they want to. Or maybe a quick mention in the docs could also work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for commenting @jtpio

Or maybe a quick mention in the docs could also work?

Since here we want to implement an actual new feature in JupyterGIS, then we should just write the needed TypeScript code in the Notebook output renderer we have.

It feels weird to open a document from there, but maybe that could be lazy e.g. if that JupyterGIS document is already opened, we should not open it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed privately with @martinRenou , we can first try embedding the DocumentWidget in the output, as started by @mfisher87 in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks all for your expertise in designing this feature! We have a holiday in the US today, so I'll make some more progress tomorrow :) @martinRenou @brichet any other context from your private conversation that might be useful?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfisher87 you can try using DocumentManager.open(), it creates both the context and the widget, and return the widget.

The following code returns the main area widget, with the toolbar, it can be a good starting point.

const widget = options.docManager.open(`RTC:${path}`);
if (widget instanceof JupyterGISWidget) {
  this._jgisWidget = widget;
  this.addWidget(this._jgisWidget);
  this._jgisWidget.show();
}

@brichet
Copy link
Collaborator

brichet commented Feb 6, 2025

FYI @mfisher87 #419 has been merged, you can probably revive or remake this PR.

@mfisher87
Copy link
Member Author

Awesome work @brichet !! I hope to have some time to play with this tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants