갈루아의 반서재


Jupyter Lab: Evolution of the Jupyter Notebook

An overview of JupyterLab, the next generation of the Jupyter Notebook.


데이터에 따르면 깃허브에만도 300만개 이상의 Jupyter Notebook이 사용되고 있다고 한다. 비단 이런 데이터를 빌리지 않고도 Jupyter Notebook의 인기는 짐작 가능하다. Jupyter Notebook은 이미 다양한 장점을 가지고 있지만 여기에 멈추지 않았고, 더욱 진화된 JupyterLab 이 나왔다. 그리고 JupyterLab 이 결국에는 Jupyter Notebook 의 자리를 대신할 것으로 기대된다. 


Installation

conda, pip, pipenv 등을 사용해 설치가능하다. 공식 문서는 여기서 확인할 수 있다.


(tfKeras) founder@hilbert:~/tfKeras$ conda install -c conda-forge jupyterlab
Collecting package metadata: done
Solving environment: done

==> WARNING: A newer version of conda exists. <==
  current version: 4.6.3
  latest version: 4.6.4

Please update conda by running

    $ conda update -n base -c defaults conda

## Package Plan ##

  environment location: /home/founder/anaconda3/envs/tfKeras
  added / updated specs:
    - jupyterlab

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    bleach-3.1.0               |             py_0         110 KB  conda-forge
    jupyterlab-0.35.4          |           py36_0        10.5 MB  conda-forge
    jupyterlab_server-0.2.0    |             py_0          21 KB  conda-forge
    nbconvert-5.3.1            |             py_1         320 KB  conda-forge
    notebook-5.7.4             |        py36_1000         7.2 MB  conda-forge
    ------------------------------------------------------------
                                           Total:        18.1 MB

The following NEW packages will be INSTALLED:
  bleach             conda-forge/noarch::bleach-3.1.0-py_0
  jupyterlab         conda-forge/linux-64::jupyterlab-0.35.4-py36_0
  jupyterlab_server  conda-forge/noarch::jupyterlab_server-0.2.0-py_0

The following packages will be UPDATED:
  nbconvert          pkgs/main/linux-64::nbconvert-5.3.1-p~ --> conda-forge/noarch::nbconvert-5.3.1-py_1
  notebook                 pkgs/main::notebook-5.7.2-py36_0 --> conda-forge::notebook-5.7.4-py36_1000

Proceed ([y]/n)? y
Downloading and Extracting Packages
jupyterlab_server-0. | 21 KB     | ##################################### | 100%
nbconvert-5.3.1      | 320 KB    | ##################################### | 100%
jupyterlab-0.35.4    | 10.5 MB   | ##################################### | 100%
notebook-5.7.4       | 7.2 MB    | ##################################### | 100%
bleach-3.1.0         | 110 KB    | ######################################################################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done


Starting JupyterLab

다음과 같은 단순한 명령만으로 실행이 가능하다.

(tfKeras) founder@hilbert:~/tfKeras$ jupyter lab
[W 08:44:16.542 LabApp] All authentication is disabled.  Anyone who can connect to this server will be able to run code.
[I 08:44:16.821 LabApp] [jupyter_nbextensions_configurator] enabled 0.4.1
[I 08:44:16.825 LabApp] JupyterLab extension loaded from /home/founder/anaconda3/envs/tfKeras/lib/python3.6/site-packages/jupyterlab
[I 08:44:16.826 LabApp] JupyterLab application directory is /home/founder/anaconda3/envs/tfKeras/share/jupyter/lab
[W 08:44:16.827 LabApp] JupyterLab server extension not enabled, manually loading...
[I 08:44:16.830 LabApp] JupyterLab extension loaded from /home/founder/anaconda3/envs/tfKeras/lib/python3.6/site-packages/jupyterlab
[I 08:44:16.830 LabApp] JupyterLab application directory is /home/founder/anaconda3/envs/tfKeras/share/jupyter/lab
[I 08:44:16.831 LabApp] Serving notebooks from local directory: /home/founder/tfKeras
[I 08:44:16.831 LabApp] The Jupyter Notebook is running at:
[I 08:44:16.831 LabApp] http://localhost:8888/
[I 08:44:16.831 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
^C[I 08:45:32.788 LabApp] interrupted
Serving notebooks from local directory: /home/founder/tfKeras
0 active kernels
The Jupyter Notebook is running at:
http://localhost:8888/

외부 IP를 이용하여 웹브라우저에서 실행하고 하면 다음과 같이 하면 된다.

tfKeras) founder@hilbert:~/tfKeras$ jupyter lab --no-browser --ip=0.0.0.0
[W 08:46:26.820 LabApp] All authentication is disabled.  Anyone who can connect to this server will be able to run code.
[I 08:46:26.847 LabApp] [jupyter_nbextensions_configurator] enabled 0.4.1
[I 08:46:26.852 LabApp] JupyterLab extension loaded from /home/founder/anaconda3/envs/tfKeras/lib/python3.6/site-packages/jupyterlab
[I 08:46:26.852 LabApp] JupyterLab application directory is /home/founder/anaconda3/envs/tfKeras/share/jupyter/lab
[W 08:46:26.854 LabApp] JupyterLab server extension not enabled, manually loading...
[I 08:46:26.857 LabApp] JupyterLab extension loaded from /home/founder/anaconda3/envs/tfKeras/lib/python3.6/site-packages/jupyterlab
[I 08:46:26.857 LabApp] JupyterLab application directory is /home/founder/anaconda3/envs/tfKeras/share/jupyter/lab
[I 08:46:26.857 LabApp] Serving notebooks from local directory: /home/founder/tfKeras
[I 08:46:26.858 LabApp] The Jupyter Notebook is running at:
[I 08:46:26.858 LabApp] http://(hilbert or 127.0.0.1):8888/
[I 08:46:26.858 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).


크롬 등 웹브라우저를 열어 http://11.222.333.44:8888/ 와 같은 식으로 입력하면 아래와 같은 실행화면을 볼 수 있다.

파이썬3 만을 사용하고 있기 때문에 아이콘은 python 3 만 표시된다. 


Interface

다양한 기능을 살펴보기에 앞선 인터페이스부터 보자.


Menu Bar 상단의 메뉴바는 쥬피터랩에서 사용가능한 다양한 액션을 보여준다.

Left Sidebar 는 자주 사용하는 탭으로 구성이 된다. 메인바의 View - Show Left Sidebar 또는 해당 탭을 클릭함으로써 보이거나 감출 수 있다. 

Main Work Area 실제 동작이 진행되는 곳으로, notebooks, documents, consoles, terminals 등으로 구성되어 있다. 파일을 더블클릭하거나 이 공간으로 드래그하면 된다.

물론 전통적인 주피터 노트북과 주피터 랩을 오갈 수도 있다. 주소창에 lab 대신 tree 라고 넣으면 된다.


Creating and Saving Files

파일 관련한 기능에 대해 살펴본다.

Creating Files

메인 메뉴의 + 아이콘을 클릭하면 된다. 클릭을 하면 메인 작업 영역에 새로운 노트북, 콘솔, 터미널, 텍스트 편집기 사용이 가능하도록 새로운 Launcher 가 뜨게 된다. 또는 메뉴바의 File 탭을 이용해도 된다.

Opening Existing Files

파일탭에서 해당 파일을 더블클릭하면 열 수 있다.


Flexible Layouts

기존의 노트북도 내장 텍스트 펹비기와 터미널을 지원하기는 했다. 하지만 잘 보이지 않았던 점도 있지만, 통합되지 않고 따로 노는 바람에 그 활용도가 떨어졌던 것도 사실이다. 하지만 주피터랩에서는 하나의 인터랙티브한 환경에서 이들을 통합했다.

Notebooks

주피터랩의노트북 문서 포맷은 노트북의 그것과 같은 것이다. 기존의 노트북 파일은 주피터랩에서도 오류없이 오픈된다. 

Console

QT 콘솔 타입 환경 유저를 위한 콘솔이 포함되어 있다. 콘솔을 통해 커널에서 코드를 실행하게 해준다.

Text Editor

파일 편집이 가능한 텍스트 에디터가 포함되어 있다. 하이라이팅 기능 등 다양한 옵션은 메뉴바의 Settings 메뉴에서 조정가능하다.

Terminal

주피터랩 터미널은 bash, tsch 등 다양한 시스템셀을 지원한다. 

혹자는 이런 기능들 모두 기존의 노트북에서 제공하던 것이 아니냐고 물어볼 수도 있겠지만, 매우 유연한 레이아웃시스템을 제공한다는 측면에서 기존의 노트북과 차별이 된다. 아래와 같이 드래그 앤 드롭을 이용해서 작업에 원하는 레이아웃을 구성할 수 있다.

Enhanced Notebook Functionality

기존 노트북에 없던 다음과 같은 기능이 추가되었다.

  • Expand and Collapse cells
  • Drag and Drop cells within the Notebook
  • Tab Autocompletion in the Editor
  • Themes


Supported File Formats

주피터랩은 다음의 포맷도 지원한다.

  • Images: jpeg, png etc and Gifs
  • geojson
  • Vegalite files, geojson files,
  • PDF Documents
  • High-Performance CSV viewer


Interactive Computing

주피터랩은 인터랙티브한 컴퓨팅을 가능하게 했다. 특히 이러한 점은 데이터 사이언스 분야에서 매우 큰 장점이 될 수 있다.

  • Creating New View for Output
  • New View on the same file
  • Dragging / Dropping and Editing Cells between Notebooks
  • Simplifying the Code Documentation Process


Extensions

주피터랩은 기본적으로 확장 환경을 고려해서 만들어졌다. 주피터랩 확장기능은 자바스크립트 개발환경의 표준 패키지인 npm 패키지이다. 이미 깃허브 등에 상당수가 올라와있으며 jupyterlab-extension 라는 토픽으로 검색가능하다. 주피터랩 익스텐션을 설치하기 위해서는 Node.js 를 먼저 설치해야 한다. 

(tfKeras) founder@hilbert:~/tfKeras$ conda install -c conda-forge nodejs
Collecting package metadata: done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.6.3
  latest version: 4.6.4

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /home/founder/anaconda3/envs/tfKeras

  added / updated specs:
    - nodejs


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    nodejs-11.10.0             |       hf484d3e_0        16.5 MB  conda-forge
    ------------------------------------------------------------
                                           Total:        16.5 MB

The following NEW packages will be INSTALLED:

  nodejs             conda-forge/linux-64::nodejs-11.10.0-hf484d3e_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
nodejs-11.10.0       | 16.5 MB   | ######################################################################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
다음과 같은 형식으로 새로운 익스텐션을 설치할 수 있다. 
jupyter labextension install my-extension@1.2.3

여기서확인할 수 있다.


예제로 Google Drive Extension 을 설치해보자.




(tfKeras) founder@hilbert:~/tfKeras$ jupyter labextension install @jupyterlab/google-drive
Node v11.10.0

> /home/founder/anaconda3/envs/tfKeras/bin/npm pack @jupyterlab/google-drive
npm notice
npm notice 📦  @jupyterlab/google-drive@0.16.0
npm notice === Tarball Contents ===
npm notice 2.7kB  package.json
npm notice 1.5kB  LICENSE
npm notice 2.5kB  README.md
npm notice 1.6kB  lib/browser.d.ts
npm notice 6.6kB  lib/browser.js
npm notice 5.4kB  lib/contents.d.ts
npm notice 14.5kB lib/contents.js
npm notice 9.3kB  lib/drive.d.ts
npm notice 46.8kB lib/drive.js
npm notice 3.3kB  lib/gapi.d.ts
npm notice 10.9kB lib/gapi.js
npm notice 203B   lib/index.d.ts
npm notice 9.7kB  lib/index.js
npm notice 338B   schema/drive.json
npm notice 393B   style/account-dark.svg
npm notice 392B   style/account-light.svg
npm notice 17.8kB style/drive_dark.png
npm notice 3.0kB  style/drive_light.png
npm notice 42.9kB style/drive.png
npm notice 2.0kB  style/index.css
npm notice 305B   style/share.svg
npm notice === Tarball Details ===
npm notice name:          @jupyterlab/google-drive
npm notice version:       0.16.0
npm notice filename:      jupyterlab-google-drive-0.16.0.tgz
npm notice package size:  86.5 kB
npm notice unpacked size: 182.2 kB
npm notice shasum:        36e87826b80ea43bd4fef0b1f08c7e9a8f9193e5
npm notice integrity:     sha512-VHKSpt1BR8NqU[...]CAwM+ikBaaSlw==
npm notice total files:   21
npm notice
jupyterlab-google-drive-0.16.0.tgz
Node v11.10.0

> node /home/founder/anaconda3/envs/tfKeras/lib/python3.6/site-packages/jupyterlab/staging/yarn.js install
yarn install v1.9.4
info No lockfile found.
[1/5] Validating package.json...
[2/5] Resolving packages...
⠠ yallist@^2.1.2(node:20321) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() metho                                          ds instead.
warning css-loader > cssnano > autoprefixer > browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
warning css-loader > cssnano > postcss-merge-rules > browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
warning css-loader > cssnano > postcss-merge-rules > caniuse-api > browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
[3/5] Fetching packages...
info fsevents@1.2.7: The platform "linux" is incompatible with this module.
info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
warning "@jupyterlab/vdom-extension > @nteract/transform-vdom@1.1.1" has incorrect peer dependency "react@^15.6.1".
[5/5] Building fresh packages...
success Saved lockfile.
warning Your current version of Yarn is out of date. The latest version is "1.13.0", while you're on "1.9.4".
Done in 34.52s.
> node /home/founder/anaconda3/envs/tfKeras/lib/python3.6/site-packages/jupyterlab/staging/yarn.js run build
yarn run v1.9.4
$ webpack
Hash: 424f37d2cfbf16fa4e27
Version: webpack 4.12.2
Time: 21855ms
Built at: 02/23/2019 9:54:58 AM
                                   Asset       Size        Chunks             Chunk Names
    674f50d287a8c48dc19ba404d20fe713.eot    162 KiB                [emitted]
  af7ae505a9eed503f8b8e6982036873e.woff2   75.4 KiB                [emitted]
    912ec66d7572ff821749319396470bde.svg    434 KiB                [emitted]
   fee66e712a8a08eef5805a46892932ad.woff   95.7 KiB                [emitted]
    06d483900b1eb3f65dc0d8b0379382c0.png   17.4 KiB                [emitted]
    b06871f281fee6b241d60582ae9369b9.ttf    162 KiB                [emitted]
    d56f3e79da8724878d9c41502956bcd1.png   41.9 KiB                [emitted]
    b1efea7ab3eceaa05d36173c0bcd54fe.png   2.97 KiB                [emitted]
            main.a41c89352fcc9fcc84de.js   53.3 KiB          main  [emitted]  main
               0.cc98107762fcc28532b3.js    4.5 KiB             0  [emitted]
            vega.91b98e783d16fd1b9e23.js  519 bytes          vega  [emitted]  vega
    vendors~main.39d8472c5e3efbee0bca.js   8.15 MiB  vendors~main  [emitted]  vendors~main
    vendors~vega.37cc6172c1474e371335.js   2.94 MiB  vendors~vega  [emitted]  vendors~vega
               1.055322dcf6c2bb19185f.js    888 KiB             1  [emitted]
        main.a41c89352fcc9fcc84de.js.map     62 KiB          main  [emitted]  main
           0.cc98107762fcc28532b3.js.map   5.73 KiB             0  [emitted]
        vega.91b98e783d16fd1b9e23.js.map  251 bytes          vega  [emitted]  vega
vendors~main.39d8472c5e3efbee0bca.js.map   9.38 MiB  vendors~main  [emitted]  vendors~main
vendors~vega.37cc6172c1474e371335.js.map   2.29 MiB  vendors~vega  [emitted]  vendors~vega
           1.055322dcf6c2bb19185f.js.map   1.04 MiB             1  [emitted]
                              index.html   1.54 KiB                [emitted]
Entrypoint main = vendors~main.39d8472c5e3efbee0bca.js vendors~main.39d8472c5e3efbee0bca.js.map main.a41c89352fcc9fcc84de.js main.a41c89352fcc9fcc84de.js.map
 [0] multi whatwg-fetch ./build/index.out.js 40 bytes {main} [built]
 [ANye] ./build/index.out.js 35 KiB {main} [built]
 [yLpj] (webpack)/buildin/global.js 489 bytes {vendors~main} [built]
 [1] vertx (ignored) 15 bytes {main} [optional] [built]
 [RnhZ] ./node_modules/moment/locale sync ^\.\/.*$ 2.88 KiB {main} [optional] [built]
 [YuTi] (webpack)/buildin/module.js 497 bytes {vendors~main} [built]
 [eTbV] ./node_modules/codemirror/mode sync ^\.\/.*\.js$ 2.78 KiB {0} [built]
 [2] util (ignored) 15 bytes {main} [built]
 [4] buffer (ignored) 15 bytes {main} [optional] [built]
 [5] crypto (ignored) 15 bytes {main} [optional] [built]
 [6] readable-stream (ignored) 15 bytes {main} [built]
 [7] supports-color (ignored) 15 bytes {main} [built]
 [8] chalk (ignored) 15 bytes {main} [built]
[10] node-fetch (ignored) 15 bytes {vega} [built]
[11] fs (ignored) 15 bytes {vega} [built]
    + 2435 hidden modules

WARNING in d3-array
  Multiple versions of d3-array found:
    1.2.4 ./~/d3-scale/~/d3-array from ./~/d3-scale/~/d3-array/src/index.js
    2.0.3 ./~/d3-array from ./~/d3-array/src/index.js


WARNING in vega-lite
  Multiple versions of vega-lite found:
    2.5.1 ./~/vega-lite/build/src from ./~/vega-lite/build/src/compile/selection/selection.js
    2.6.0 ./~/vega-lite/build from ./~/vega-lite/build/src/index.js

Check how you can resolve duplicate packages:
https://github.com/darrenscerri/duplicate-package-checker-webpack-plugin#resolving-duplicate-packages-in-your-bundle

Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
    [KTNU] ./node_modules/html-loader!./templates/partial.html 567 bytes {0} [built]
    [YuTi] (webpack)/buildin/module.js 497 bytes {0} [built]
    [aS2v] ./node_modules/html-webpack-plugin/lib/loader.js!./templates/template.html 1.22 KiB {0} [built]
    [yLpj] (webpack)/buildin/global.js 489 bytes {0} [built]
        + 1 hidden module
Done in 24.66s.