This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

JupyterLab

    JupyterLab configuration and details for Piglet Run.

    Overview

    Piglet Run includes JupyterLab for interactive computing and data analysis.

    Access

    Default URL: http://<ip>/jupyter

    Configuration

    File: /etc/piglet/jupyter.yml

    jupyter:
      enabled: true
      port: 8888
      token: ${JUPYTER_TOKEN}
    
      # Notebook directory
      notebook_dir: /home/dba/notebooks
    
      # Allowed origins
      allow_origin: "*"
    
      # Kernels
      kernels:
        - python3
        - ir
        - julia
    

    JupyterLab Configuration

    File: /home/dba/.jupyter/jupyter_lab_config.py

    c.ServerApp.ip = '127.0.0.1'
    c.ServerApp.port = 8888
    c.ServerApp.open_browser = False
    c.ServerApp.notebook_dir = '/home/dba/notebooks'
    c.ServerApp.token = ''
    c.ServerApp.allow_origin = '*'
    

    Available Kernels

    KernelLanguageDescription
    python3PythonIPython kernel
    irRR kernel
    juliaJuliaJulia kernel
    bashBashBash kernel

    Install Additional Kernels

    # R kernel
    R -e "IRkernel::installspec()"
    
    # Julia kernel
    julia -e 'using Pkg; Pkg.add("IJulia")'
    

    Pre-installed Extensions

    ExtensionDescription
    jupyterlab-gitGit integration
    jupyterlab-lspLanguage server protocol
    jupyterlab-sqlSQL support

    Install Extensions

    pip install jupyterlab-git
    jupyter labextension install @jupyterlab/git
    

    Service Management

    # Start Jupyter
    pig start jupyter
    
    # Stop Jupyter
    pig stop jupyter
    
    # Restart Jupyter
    pig restart jupyter
    
    # View logs
    pig logs jupyter
    

    Connecting to PostgreSQL

    import psycopg2
    import pandas as pd
    
    # Connect to database
    conn = psycopg2.connect(
        host="localhost",
        database="postgres",
        user="dba"
    )
    
    # Query data
    df = pd.read_sql("SELECT * FROM my_table", conn)
    df.head()
    

    Using SQL Magic

    %load_ext sql
    %sql postgresql://dba@localhost/postgres
    
    %%sql
    SELECT * FROM pg_stat_activity LIMIT 5;
    

    Keyboard Shortcuts

    ShortcutAction
    Shift+EnterRun cell
    Ctrl+EnterRun cell, stay in cell
    Alt+EnterRun cell, insert below
    EscCommand mode
    EnterEdit mode
    AInsert cell above
    BInsert cell below
    DDDelete cell

    Troubleshooting

    Connection Issues

    # Check service status
    systemctl status jupyter
    
    # Check port binding
    ss -tlnp | grep 8888
    
    # View logs
    journalctl -u jupyter -f
    

    Kernel Issues

    # List available kernels
    jupyter kernelspec list
    
    # Reinstall kernel
    python -m ipykernel install --user
    

    See Also