If the default environments available in the Application Configuration dropdown menu found in the Cloud Environments widget don't come with all of the packages you consistently need, and you'd like a more efficient way of launching a Jupyter notebook without having to install each package manually when you create a new notebook, you may want to use a startup script to streamline this process.
Not only are startup scripts good for installing packages, they're also capable of making environment changes that typically require sudo. This makes them an efficient alternative to creating custom docker images (if you're curious about doing that, check out this tutorial). While a custom docker is a great way to take a snapshot of a set of package versions to keep your environment consistent, using a startup script is quick way to add anything you need - including updated packages - to whatever docker image you're working with, whether you're using a custom docker or one of our pre-configured ones. Startup scripts are supported for both Jupyter environments and RStudio environments.
In this short tutorial, you'll see an example of a startup script, how to upload that startup script, how to find the file path you'll need to provide as a link, and how to use that link to launch your custom cloud environment.
Below is the example startup script we'll be using in this tutorial. This startup script installs the "multtest" package that's part of Bioconductor, but is not included in Terra's default R/Bioconductor environment.
We can start with a quick sanity check - let's make sure the package we're interested in isn't already part of the default environment. We'll start by opening the Cloud Environment widget and selecting the default R/Bioconductor image in the Application Configuration dropdown menu:
Before we add our custom startup script in our compute profile, we'll do our quick sanity check by trying to import that package. You should see an error saying that no such package is currently on your virtual machine:
Next, we'll add a startup script to our cloud environment, for which we'll first need a URI to use as the link. You can upload the startup script to any Google bucket, provided your workspace can access to that bucket. For the purpose of this tutorial, we've uploaded the startup script file to the dedicated workspace bucket by going to the Data tab of the workspace, selecting the "Files" section at the bottom of the lefthand menu, and clicking the "Upload" button in the bottom right.
Once the file is in our workspace bucket, go to the Google Cloud Console where you can copy the URI of your script file. You can do this either with the link to your bucket found on the right-hand side of your workspace dashboard, or by clicking the file link in the Data tab:
Once you have this URI copied, paste that URI into the Startup Script field under the Cloud Compute Profile section of the Cloud Environment widget, and click "Upload" or "Create".
Once your environment is ready, you can launch a notebook. If you run the same command we attempted during the sanity check at the beginning of this tutorial, you should now be able to successfully import this package: