This blog is powered by enaml-web and Jupyterlab as an admin backend. Jupyterlab happens to be great for doing everything, including writing and previewing markdown as well as testing any code you have.
So how does it work? Simple, jupyterlab's backend is tornado, a simple
pip install jupyterlab get's jupyterlab and it's dependencies installed. But by default Jupyterlab launches to Jupyterlab itself, so to customize it we'll have to use the jupyterlab_server to add hooks in to have it display our pages.
As the docs explain, just subclass the
LabServerApp then we can hook in with our own request handlers. For example:
import tornado.web from jupyter_server.app import LabServerApp class HomeHandler(tornado.web.RequestHandler): def get(self): # Whatever you want the home page to be self.write("Hello, world") class CustomApp(LabServerApp): def start(self): self.init_site() super(CustomApp, self).start() def init_site(self): # Add tornado handlers here custom_handlers = [ (r"/", HomeHandler), # And others etc.. ] self.web_app.add_handlers('.*$', custom_handlers)
custom_handlers is a list of urls and RequestHandlers like you would pass to any other tornado Application.
Just doing this however, Jupyterlab will still redirect to the lab application, but we can change that too. The easiest method I've found is just to pass the configuration directly to the
launch_instance call like this:
import os from app import CustomApp def main(): CustomApp.launch_instance( # Whatever your server port needs to be port=8888, # Listen on all ports ip='*', # Where you want jupyterlab to be base_url='/jupyterlab/', notebook_dir='data/', debug=False, open_browser=False, # Set the hashed password password=os.environ.get('HASHED_PWD') ) if __name__ == '__main__': main()
You'll want to create the
HASHED_PWD by using
from notebook.auth import passwd passwd()
Then just run that file using however you like to deply stuff
Note: I highly recommend running in a container like docker
At some point, I'll cover how the enaml-web stuff works, for now, enjoy go give Jupyterlab a try!
What other blog admins have tabs, split panes, and full IPython access? None that I know of, it's great!
Updated to correct hashed passwd usage