localtileserver icon indicating copy to clipboard operation
localtileserver copied to clipboard

Configure jupyter server extension

Open banesullivan opened this issue 3 years ago • 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"

banesullivan avatar Jul 18 '22 20:07 banesullivan

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: https://github.com/davidbrochart/ipyurl/issues/2#issuecomment-1397803934

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

artttt avatar Jan 20 '23 05:01 artttt

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 😄 )

banesullivan avatar Jan 20 '23 16:01 banesullivan

@artttt Could your solution work on AWS SageMaker?

giswqs avatar Jan 20 '23 16:01 giswqs

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

(ref #128)

banesullivan avatar Jan 20 '23 16:01 banesullivan

@banesullivan No worries. Let's explore this.

giswqs avatar Jan 20 '23 16:01 giswqs

@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. https://github.com/davidbrochart/ipyurl/issues/2#issuecomment-1397803934

artttt avatar Jan 23 '23 02:01 artttt

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}}"

https://github.com/davidbrochart/ipyurl/issues/2#issuecomment-1397803934 image

image

giswqs avatar Jul 26 '23 01:07 giswqs