I’m trying to create a dropdown in jupyter lab app which will show the existing conda environment for the users to select and activate it before starting the session.
I’m following Dynamic Behavior - Issue - Get Help - Open OnDemand although Im getting some error when loading the form . I dont think it is ruby error because it runs well as a ruby file . I believe it has to do something with ruby code in .yml (form.yml) . I’d really appreciate if you can take a look and tell me if there is something I doing wrong with ? Please advise. Thanks !
Code:
<%-
require ‘open3’
cmd=“/hpc/apps/anaconda3/2022.5/bin/conda env list | awk ‘{print $1}’ | tail -n +3”
stdout, stderr, status = Open3.capture3(‘bash’,stdin_data: cmd)
conda_envs =
if status.success?
stdout.split(“\n”).each do |env|
conda_envs.append(env)
end
puts conda_envs
else
abort ‘error: could not execute command’
end
-%>
Please find below corrected version …
I dont believe this is the syntax error on line 4. The same code works fine as ruby file . But , whenever I try to integrate it in .yml file it throws such error .
Can you please take a look at it now ? Thanks !
<%-
require 'open3'
cmd="/hpc/shared/apps/anaconda3/2022.5/bin/conda env list | awk '{print $1}' | tail -n +3"
stdout, stderr, status = Open3.capture3('bash',stdin_data: cmd)
conda_envs = []
if status.success?
stdout.split("\n").each do |env|
conda_envs.push(env)
end
puts conda_envs
else
abort 'error: could not execute command'
end
-%>
---
cluster: "pbs"
attributes:
modules: "singularity/3.3-rhel7"
extra_jupyter_args: ""
memory:
widget: "number_field"
max: 100
min: 4
step: 1
label: "Memory (GB)"
widget: “select”
label: “Conda environment”
options:
<%- conda_envs.each do |h| %>
- <%= h %>
<%- end %>
form:
- modules
- extra_jupyter_args
- bc_queue
- bc_num_hours
- bc_num_slots
- bc_email_on_started
- memory
- conda_envs
I go this working in this file. You’ll need to change the cluster and conda location as those are specific to my system.
You have a few issues:
First you need the yml.erb extension. The system was reading this file as straight YAML which it wasn’t. Because it had no erb extension - it did not process it correctly.
Secondly - you have issues with what I assume is conda_envs. You see your widget is not indented correctly along with other fields that pertain to conda_envs.
Thanks . I believe I did many trials which explains the typo in second indention. Well , having no .erb extension was the problem . Thank you so much ! I could’nt have figure it out without your assistance . Appreciate it