Usage — Remote use

This page describes how to run ClimCanvas on a remote machine such as a lab server and operate it from the browser on your own PC. The app, the netCDF data, and the session save location all live on the server side; only the browser screen reaches your PC. Figures you create (PNG etc.), animations, and reproduction scripts are saved by downloading them to your PC through the browser. See local use if everything should run on your own PC, and classes and demos for temporary use where several people connect to one PC.

REMOTE

Remote mode

Each user connects to their own ClimCanvas via SSH. Data and privileges stay separate.

1. Launching the app (connection flow)

We recommend an SSH tunnel (port forwarding) for the connection. Authentication and encryption are left to SSH, so the Streamlit port never has to be exposed to the network. 1.1 explains the basic connection flow, and 1.2 and 1.3 introduce settings that make each launch easier (the Streamlit config file and a shell function). 1.4 then describes a better-protected way to launch on a shared server where the administrator assigns ports. Configuring the allowed directories for data loading, which is practically mandatory in remote use, is described in Install 3.3.

1.1 Basic connection flow

The simplest flow, in which a single SSH session serves as both the login and the tunnel, is as follows.

# ① In a terminal on your PC — log in to the server while opening the tunnel
$ ssh -L 8501:localhost:8501 you@server.example.ac.jp
 
# ② On the server you logged in to — activate the Python environment and launch the app ($IDIR = installation directory)
$ conda activate env_name # your usual analysis environment (Install 1.3)
$ cd $IDIR/climcanvas
$ streamlit run app.py --server.headless=true --server.address=127.0.0.1
 
# ③ Open http://localhost:8501 in the browser on your PC

1.2 Skip typing the launch options every time (~/.streamlit/config.toml)

The two options in step ② of 1.1 can be omitted if you put a Streamlit config file in your home directory on the server. From then on, streamlit run app.py alone is enough to launch.

# ~/.streamlit/config.toml (placed on the server — applies to your account only)
[server]
headless = true
address = "127.0.0.1"

1.3 Launch from any directory (shell function)

streamlit run can be launched from any directory if you give app.py as an absolute path (Streamlit automatically adds the directory containing app.py to the import search path). The working directory (current directory), however, stays where you launched from, so the initial value data/sample/sample_atmos.nc of the "Path to netCDF file" field and the relative-path form of reproduction scripts (FAQ) are interpreted relative to that location. We therefore recommend writing a shell function in ~/.bashrc that does cd to the installation directory before launching. If you write the full path to python, conda activate is no longer needed either. Write the actual paths, not the placeholder $IDIR used on this page (the example below assumes ClimCanvas is in $HOME/climcanvas and the Python environment in $HOME/miniforge3/envs/myenv).

# Append to ~/.bashrc (on the server; ~/.zshrc for zsh). Adjust the two paths to your environment
climc() {
    ( cd "$HOME/climcanvas" && \
        "$HOME/miniforge3/envs/myenv/bin/python" -m streamlit run app.py \
            --server.headless=true --server.address=127.0.0.1 \
            --server.port="${1:-8501}" )
}
 
# Launch (from anywhere; no cd or activate needed)
$ climc # launch on port 8501
$ climc 8502 # change the port (also change the tunnel destination on your PC)

1.4 When the administrator has assigned ports (start-climcanvas.sh)

On a multi-user server where the administrator has assigned a port to each user (Install — Setup for remote environments), launch with the bundled launcher. The launcher looks up your port number in the port table automatically and launches with all the options required for protection. Use your own port number as the tunnel destination (the second number) in ① on your PC (the assignment is fixed, so it is the same number every time; the first, PC-side port is free to choose, as in 1.1). You can also launch manually, but a wrong port or option disables the protection, so for safety we strongly recommend launching via the launcher.

# ① In a terminal on your PC — log in while opening a tunnel to your own port number (e.g. 8505)
$ ssh -L 8501:localhost:8505 you@server.example.ac.jp
 
# ② On the server you logged in to — activate the Python environment and launch via the launcher (the port is taken from the table automatically)
$ conda activate env_name # the launcher uses the python3 on PATH (the activated environment)
$ cd $IDIR/climcanvas
$ scripts/server/start-climcanvas.sh
 
# ③ Open http://localhost:8501 in the browser on your PC

Specifying the python to use (skipping activate)

To launch without activating the environment, set CLIMCANVAS_PYTHON to the python of your environment as a full path. If you put it in ~/.bashrc or similar, you can thereafter launch with just the same commands as ② above, without activate.

# One line in ~/.bashrc (takes effect on every subsequent login)
export CLIMCANVAS_PYTHON=$HOME/miniforge3/envs/myenv/bin/python
 
# Launch (no activate needed)
$ cd $IDIR/climcanvas
$ scripts/server/start-climcanvas.sh

An even easier launch (alias / PATH)

The launcher resolves the location of app.py from its own location (the script file), so it can be launched from any directory. Set up an alias or PATH in ~/.bashrc and cd is no longer needed either. Write the actual path, not the placeholder $IDIR used on this page (the example below assumes an installation in /opt/climcanvas).

# Method 1: alias (one line in ~/.bashrc) → from then on, launch from anywhere with climc
alias climc='/opt/climcanvas/scripts/server/start-climcanvas.sh'
 
# Method 2: add to PATH (one line in ~/.bashrc) → from then on, launch from anywhere with start-climcanvas.sh
export PATH="/opt/climcanvas/scripts/server:$PATH"

Reference: launcher environment variables

Environment variableDefaultPurpose
CLIMCANVAS_PYTHONpython3The python executable to use. Give the full path to launch without activating an environment (above; also useful to keep the app and the generated scripts on the same environment)
CLIMCANVAS_ALLOWED_DIRS(none)Directories of netCDF files that can be opened (:-separated). Overrides allowed_dirs in the config file for that process only (Install 3.3)
CLIMCANVAS_APP_DIRTwo levels above the script (repository root)The directory containing app.py. Needs to be set only when the script has been copied outside the repository
CLIMCANVAS_PORTS_TABLE/etc/climcanvas/ports.tsvPath to the port table (normally no change needed)

2. Saving and restoring work in progress (sessions)

A session file is the complete set of settings of a figure you created — the paths of the loaded netCDF files, the panel layout, the plot settings and so on — stored as a single JSON file. By saving it, you can pick up where you left off next time (restore). In remote use there are two methods, depending on whether the file stays on the server or is brought to your PC. Both restoring ("Restore session") and saving ("Save" → "Session") are split into a pair of tabs, "server (blue) / upload and download (orange)", and the origin of the session being edited can always be checked in the banner of the same color above the figure. To have the blue tab labeled "From the server" / "To the server", set mode = "remote" in config.toml on the server (without it, the labels are "From this PC" / "To this PC", intended for local use).

Method A: Save under a name on the server (to resume on another day)

  1. Save: from the "Save" → "Session" → "To the server" tab. The file is stored on the server side; nothing is left on your PC.
  2. Restore: from the "From the server" tab of "Data & session loading" → "Restore session". On the following days too, connect to the same server and you can resume right from the start-up screen.

The save/restore behavior depends on whether session_dirs is set in the config file on the server (config file details).

  • Without session_dirs (default): the save location is fixed to a single place, ~/.climcanvas/sessions/ on the server (the folder is created automatically on the first save). "Destination directory" has only one choice, and the restore side shows no directory selection at all.
  • With session_dirs: several candidate locations can be registered, and the directory can be switched on both the save and restore sides (a "Directory" selection also appears on the restore side). If you include a shared project directory among the candidates, you can also hand a session over to collaborators on the same server.

Method B: Upload and download

  1. Save: with the "Save session" button in the "Save" → "Session" → "Download" tab. The file goes wherever your browser's download settings specify. The file name is free; you can name it at save time or rename it afterwards (a file of any name can be restored).
  2. Restore: upload that JSON from the "Upload" tab of "Data & session loading" → "Restore session". It can also be loaded into ClimCanvas on a different server. After loading, the uploader switches to a "Loaded: …" display; to replace it, press "Load a different session file" and upload again.

Notes on restoring