Jupyter notebook working directory


Is there a way to set the directory for my Jupyter Notebook in the form.yml file? For instance, can users choose the directory when launching a Jupyter Notebook?

In the “ondemand/data/sys/dashboard/batch_connect/sys/jupyter/output/” folder, I noticed that the before.sh script sets “c.NotebookApp.notebook_dir” to “‘${HOME}’”.


Hi, thanks for the question.

As you noticed, the answer is sure! By changing that you can set a new directory to be set when the any user runs the notebooks. And it can be something static or dynamic.

To allow the user to choose is a bit different, but yes! You could provide choices to the user to do this, but it is more involved. You will need to present the user with choices in the form.yml.erb and there are some ways to have dynamic values created to be handed back as options for a ‘widget’ such as 'select` to be presented as choices.

If you look at the form.yml.erb in the repo we maintain for Jupyter, you can see an example of what I mean:

At the top, notice the ruby ERB code:

  groups = OodSupport::User.new.groups.sort_by(&:id).tap { |groups|

It is getting information about the user’s groups back, to then use in the form as an option for the select under the attribute of account, by presenting the user with all the groups they belong to:

    label: "Project"
    widget: select
      <%- groups.each do |group| %>
      - "<%= group %>"
      <%- end %>

You could do a similar thing to have some code run on the backend to return values and be used as choices for the user to select and hand back for submission.

Now, you will need to also use some ERB in the script.sh in the template as well, since you need to ensure that what is handed back is known to the backend since you’ve defined it on the front. The way to do this is to use the context object, and just keep track of that under the form entry (any entry there is available on the backend as context.account or context.node_type as examples). So, again using the pattern of some ERB at the top of the file to make some variables and then handing them off like so:

<% front_end_form_data = context.account %>

cd <%= front_end_form_data %>

And again, if you look at something like the rstudio app we have and checkout the script.sh there you will see this used:

Let me know if you have some more specific questions on working with this.

1 Like

Hi Travis!

Thank you very much for the information and the answer!
I will run some tests, but this has already given me good guidance, thank you!

Hi Travis,

Another question, is it possible for users to have access to other directories on Jupyter? Currently, only the $HOME/notebook directory is available upon launching the Notebook. If users can access other directories, it would already meet our needs.


It appears that whatever the NOTEBOOK_ROOT is is the top level directory (root) that you can’t navigate above.

Maybe symlinks in the $HOME to other directories could suit your needs.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.