Skip to main content

Application Tips

This page lists tips that are useful for running applications within the TRE.

JupyterLab kernels

To run different environments and languages within JupyterLab it is necessary to tell Jupyter which you want available by registering the kernels.

Python Conda Environments

To use a Conda environment within JupyterLab, you need to register its kernel as follows:

  • Open Anaconda Prompt
  • Enter the following commands, replacing <nameofenvironment> as appropriate:
conda activate <nameofenvironment>
python -m ipykernel install --name <nameofenvironment> --display-name "Python (<nameofenvironment>)"

When you next open JupyterLab you will find a new kernel called Python (<nameofenvironment>) available.

R

To use R within JupyterLab, you need to register its kernel as follows:

  • Open Rstudio
  • Enter the following commands:
setwd('C:/tools/Anaconda3/Scripts')
IRkernel::installspec(name = 'ir432', displayname = 'R 4.3.2')

When you next open JupyterLab you will find a new kernel called R 4.3.2 available.

Stata

To use Stata within JupyterLab, you need to register its kernel by running:

conda activate stata
python -m nbstata.install

You may see a syntax warning, but this is safe to ignore.

When you next open JupyterLab you will find a new kernel called Stata (nbstata) available.

VS Code

We have provided a number of extensions, however they are installed during the startup of a new workspace. Please wait for windows to be totally ready, you can tell by the desktop wallpaper changing from a windows default one to one specific to your TRE environment.

Once that is done they need to be registered. This should happen when you open VS Code. However it it does not, wait while VS Code fully loads (or click the extensions button and wait for the blue clock to go away), then close and re-open VS Code.

Windows Configuration

Alt+Tab to cycle through windows

In order to have Alt+Tab work as expected, we need to configure a few things. When you are sat at a physical computer, your web browser is connected to another computer, which has a remote desktop connection to another computer: that is your workspace.

Mac Users

Mac users, once their web browser is connected to the workspace, should go to Preferences > General > Keyboard and set Use Option ⌥ as a local modifier.

Within the web browser there is a small bar at the top which is minimised. Hover over that bar and click the keyboard item to Grab all keyboard events.

Configure Grab all keyboard events

Option(⌥)+Tab should now work as Alt+Tab does.

If you should wish to have Command (⌘)+TAB work as Alt+Tab then remap your modifier keys (not recommended) by going to System Settings, searching for "modifier keys" and switching Command ⌘ key and Option ⌥ key around.

Windows users

We are investigating how to achieve the same effect from a Windows physical computer.

Adding your own command files and packages

The workspace images come with many add-ons (eg Stata .ado files) and packages (eg R and Python) included.

info

If you want additional add-ons or packages, these should be requested via the Teams channel linked at the bottom of this page.

warning

It is still possible to add your own add-ons or packages, following these steps, though this is discouraged.

You will have to repeat these steps for each workspace you start and it will only be available to you.

Python packages for Windows and Linux Instances

Details will be added here once we have tested them

Python packages in SageMaker

Python Packages should be installed into environments (venvs) under "${HOME}/SageMaker/venvs" and Jupyter Kernels under "${HOME}/SageMaker/.jupyter". We have added scripts to the SageMaker setup to preserve these venvs and Kernels when SageMaker is stopped and started again.

For example, in a JupyterLab Terminal run

pip-setup
python -m venv "${HOME}/SageMaker/venvs/my-torch-env"
source "${HOME}/SageMaker/venvs/my-torch-env/bin/activate"
pip install torch ipykernel
python -m ipykernel install --name "my-torch-env" --prefix "${HOME}/SageMaker/.jupyter"
sync-jupyter-kernels

After a minute the new kernel should appear in the Jupyter Start screen and be available in the Switch Kernel options. To see the kernel sooner select a different kernel and then Switch again to see the updated list of Kernels.

R packages

To add your own R files:

  1. Use an existing or create a Study of type "My Studies".

  2. Install the package on your local machine using the same version of R that your workspace has installed (this should be the latest version available in most cases). If you need to upgrade R on your local machine, do so first.

  3. Find the directory for the package; the command .libPaths() will tell you where it could be.

  4. Copy those files to your Study.

  5. Using a workspace with this study attached, copy the files to the correct library location. Running .libPaths() will tell you where that is.

Stata ado files

To add your own Stata ado files:

  1. Use an existing or create a Study of type "My Studies".

  2. Install the ado files on your local machine, for example using ssc install.

  3. Find the ado and other files, which will be in your home directory under ado/plus/<first-letter-of-ado-command>/<command-name>. You can type which <command-name> in Stata to find this path.

  4. Copy the files to your Study.

  5. Using a workspace with this study, attached copy the files to C:\Users\Administrator\ado\plus\<first-letter-of-ado-command> (for Windows) or $HOME/ado/plus/<first-letter-of-ado-command> (for Linux).

Problems?

If you experience issue with applications or need a hand please contact us in the LSE-Trusted-Research-Environments Teams channel