Pluto.jl¶
Operating System:
Terminal:
Shell:
Editor:
Package Manager:
Programming Language:
Utility:
Extension:
Pluto.jl is a modern, interactive notebook environment for the Julia programming language. It is designed to provide a reactive, intuitive, and lightweight interface for coding, data analysis, teaching, and exploration.
Key Features of Pluto.jl:
Reactive execution: Pluto automatically re-evaluates cells when dependencies change, ensuring that the notebook's output is always consistent with the input.
Lightweight and user-friendly: With minimal setup requirements and an intuitive interface, Pluto is ideal for beginners, educators, and data scientists.
Dynamic visualizations: Its live execution model allows users to visualize and understand code behavior dynamically, making it great for prototyping and data exploration.
For more details, visit the Pluto.jl documentation.
Setting Up Julia Environments¶
Julia environments allow you to manage packages and dependencies in an isolated manner. Using a custom JULIA_DEPOT_PATH
simplifies environment setup and ensures consistent behavior across deployments.
Creating a custom Julia environment¶
To create a custom Julia environment during a job, follow these steps:
Open the app's terminal interface and set the
JULIA_DEPOT_PATH
environment variable:export JULIA_DEPOT_PATH=/work/depot:$JULIA_DEPOT_PATH
/work/depot
specifies the directory for storing the environment and compiled packages.
Create and activate a new environment, then add packages:
julia -e 'import Pkg; Pkg.activate("my_env", shared=true); Pkg.add(["package1", "package2"])'
my_env
is the name of the custom environment.Replace
package1
andpackage2
with the desired package names.
After creating the environment, the /work/depot
directory will have the following structure:
/work/depot/
├── compiled
│ └── v1.11
├── environments
│ └── my_env
├── logs
│ ├── artifact_usage.toml
│ └── manifest_usage.toml
├── packages
│ ├── package1
│ └── pakcage2
├── registries
└── scratchspaces
The depot
folder will remain accessible on UCloud after the job completes.
Activating the custom environment in Pluto¶
To use the custom environment in a Pluto notebook:
Import the
depot
folder into the application via the Select folders to use option.Open a Pluto notebook and activate the environment by running:
import Pkg Pkg.activate("my_env", shared=true)
View the installed packages in the environment:
Pkg.status()
Pluto Notebook Settings¶
Automatically opening a notebook file: You can specify the path to a Pluto notebook file that should open automatically when the server starts. This is particularly useful for predefined workflows or presentations.
Optimizing performance with distributed workers: Pluto can use multiple distributed Julia workers for parallel computation. This is especially beneficial for large-scale data analysis or computations.
Automating Initialization¶
When starting the Pluto app, you can use the Initialization optional parameter to specify a script that pre-installs the required Julia packages. This approach installs the packages dynamically at the app's startup without creating a persistent Julia environment.
Here’s an example of a Bash script for installing Julia packages before starting Pluto:
#!/bin/bash
# Function to display an error and exit
function exit_err {
echo "$1" >&2
exit 1
}
# Array of package specifications (name and version separated by a colon)
JULIA_PACKAGES=( "DataFrames" "RDatasets" )
# Build the Julia code to install packages with specified versions
JULIA_CODE="
using Pkg
"
for pkg_spec in "${JULIA_PACKAGES[@]}"; do
IFS=':' read -r pkg version <<< "$pkg_spec"
if [ -n "$version" ]; then
JULIA_CODE+="
println(\"Installing $pkg@$version...\")
Pkg.add(PackageSpec(name=\"$pkg\", version=\"$version\"))
println(\"$pkg@$version installed successfully.\")
"
else
JULIA_CODE+="
println(\"Installing $pkg...\")
Pkg.add(\"$pkg\")
println(\"$pkg installed successfully.\")
"
fi
done
# Run the Julia code
echo "Installing Julia packages with specified versions..."
julia -e "$JULIA_CODE" || exit_err "Failed to install Julia packages."
echo "Julia package installation completed successfully."
Customize the JULIA_PACKAGES
array with the packages you need.
Contents