Snippet $51 authored by Steve Weber


Using nbgrader on local exchange

using the local /srv/nbgrader/exchange to manage files and enable formgrader.


Using your user from the jupyter website, access [create > terminal].

Note: replace <course_id> with the name of your course.

First thing we willl do is create the the files needed for the course. Laying out the files for your class can be done using nbgrader quickstart.

cd ~
nbgrader quickstart <course_id>

Users connecting to jupyter wont have some nbgrader extensions enabled by default so we will want to do this for them. We will also want to give them a default so they point to the correct course. To preform this step We'll need to use sudo to switch to root.

sudo su

cat > /runonce << 'EOF'
echo "******** $USER ********"
cd $HOME
nbgrader extension activate
cat > $HOME/ << 'EOFF'
c = get_config()
c.NbGrader.course_id = '<course_id>'
vi /runonce

for u in `ls /home` ; do 
    sudo -Hs -u $u sh /runonce

# use exit to return to your user

Update the course/nbgrader_config so it has your:

  • course_id
  • students
  • formgrade config
    • graders
    • proxy_token
    • hubapi_token
cd ~/<course_id>
sudo cat /etc/jupyter/
# set the following using the values found in the file above.

cat > << EOFFF
c = get_config()
c.NbGrader.course_id = '$(basename $(pwd))'
c.NbGrader.db_assignments = [dict(name='ps1')]
c.NbGrader.db_students = []
with open('$HOME/classlist.csv', 'r') as f:
    for l in f:
        csv = l.replace('\n', '').split(',')
            'id': csv[0],
            'first_name': csv[3],
            'last_name': csv[2],
c.FormgradeApp.ip = ''
c.FormgradeApp.port = 9000
c.FormgradeApp.authenticator_class = "nbgrader.auth.hubauth.HubAuth"
c.HubAuth.hub_base_url = 'https://$(hostname -f)'
c.HubAuth.hub_port = 443
c.HubAuth.notebook_url_prefix = '$HOME/'
c.HubAuth.graders = ['$USER']
c.HubAuth.proxy_token = u'$PROXY_TOKEN'
c.HubAuth.hubapi_token = u'$HUBAPI_TOKEN'

With the course created and students able to access assigned assiments, you can now proceed to create/edit assiments.

using jupyter's editor open: `<course_id>/source/ps1`
NOTE: when editing the menu item `View > 'Cell Toolbar' > 'Create Assignment'`
can be used to access more gui options.

assign work and release the assiment to students using the nbgrader exchange.

cd ~/<course_id>
nbgrader assign ps1

# release the assign to students
sudo mkdir -m 0755 /srv/nbgrader
# TODO: not sure what the mode on directories should be docs (chmod ugo+rw)
sudo mkdir -m 0777 /srv/nbgrader/exchange
nbgrader release "ps1"
# test
nbgrader list


To start the formgrade tool

  • open a new jupyter terminal
    • run the followfing
    • leave terminal running untill your done or indefently cd ~/<course_id> nbgrader formgrade --debug [FormgradeApp | INFO] Proxying /hub/nbgrader/<course_id> --> [FormgradeApp | INFO] Serving MathJax from /usr/local/lib/python3.5/dist-packages/notebook/static/components/MathJax/MathJax.js [FormgradeApp | INFO] Form grader running at [FormgradeApp | INFO] Use Control-C to stop this server ... > WARN: nbgrader docs say formgrade should only have one user using it at a time!

Since we configured the formgrade tool to use HubAuth you should access the webpage through the jupyterhub proxy (you cant access it directly on port 9000)



(A) from web interface

tab assignments

(B) from terminal

## optional
nbgrader list
nbgrader fetch --course <course_id> "ps1"
# work
nbgrader submit "ps1"
# see what was submited
nbgrader list --inbound