banesullivan/localtileserver

Configure jupyter server extension

banesullivan opened this issue ยท 7 comments

I'd like to see if we could use a jupyter-server extension to improve using localtileserver in remote jupyter environments to resolve issues like #95

cc @12rambau

reference: https://jupyter-server.readthedocs.io/en/latest/developers/extensions.html#server-extensions

when I get some free time, I will look into this and hopefully implement a solution that will "just work"

Hi Bane,
Am i right to assume that the idea here is to grab the url from a users browser window and parse it to set up licaltileserver?

If so have a look at my code here:
davidbrochart/ipyurl#2 (comment)

ive been using this in the jupyterhub environment i work on successfully to set up localtileserver with the following code

import os
import urllib
def init_hub():
    '''
    initialises environment variables needed to make localtileserver work on jupyter hub
    '''    
    url = window_url()
    os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = f"{os.environ['JUPYTERHUB_SERVICE_PREFIX'].lstrip('/')}proxy/{{port}}"
    up = urllib.parse.urlparse(url)
    os.environ["LOCALTILESERVER_CLIENT_HOST"] = url[: -(len(up.path))].rstrip("/") + "/"

I hope that helps

Am i right to assume that the idea here is to grab the url from a users browser window and parse it to set up licaltileserver?

That is one way to go about it if you can get it to work (I struggled to initially).

ive been using this in the jupyterhub environment i work on successfully to set up localtileserver with the following code

This is fantastic! Thank you for sharing! I will test this out when I have some time (localtileserver is hobby project so it can be tough for me to make proper time to address things ๐Ÿ˜„ )

@artttt Could your solution work on AWS SageMaker?

Sorry for my delay looking into SageMaker, @giswqs ๐Ÿ˜„ ... tough to find time for this hobby project at the moment

(ref #128)

@banesullivan No worries. Let's explore this.

@giswqs ive not tried AWS SageMaker so im not sure but as long as you can install the required package/s then it is worth a try. You may have to modify the parsing of the url to suit. Hopefully @banesullivan gets a chance to incorporate a generic solution into localtileserver.

Note: i've updated the comment that i linked to above with an additional code sample.
davidbrochart/ipyurl#2 (comment)

giswqs commented

I just tried the method @artttt provided on SageMaker Studio, it does not work. Any other method for getting the URL prefix?

Note that it is SageMaker Studio, not Studio Lab. They are different products. The method that works for Studio Lab does not work for SageMaker Studio

import os
os.environ['LOCALTILESERVER_CLIENT_PREFIX'] = f"studiolab/default/jupyter/proxy/{{port}}"

davidbrochart/ipyurl#2 (comment)
image

image