A Python admin tool for rendering subaccount hierarchy graphs for the Canvas LMS
In my line of work, oftentimes, I'm having to explain the subaccount structure of our institutional Canvas LMS to vendors and various stakeholders. So I wrote this small admin tool to help me out with just that and figured it would be useful to other Canvas admins as well, especially those having to deal with complex org structures.
The tool makes use of the Canvas API to load a subaccount (along with its nested subaccounts) of your choice (provided you're an Admin in said subaccount) and employs D3.JS to render tree-graphs that represent the subaccount hierarchy. You're able to adjust the root node to inspect each nested subaccount individually or in a holistic way, and export the raw JSON data for the graphs to pass to any visualisation platform/application of your choice.
The tool is written in Python using the Eel library and can be run locally without any web servers.
-
Install the latest version of Python from https://www.python.org/downloads, ensuring that you've added Python to your
PATH
(more on this here: https://realpython.com/add-python-to-path). -
Clone this repository in your machine or download the project files via
Code > Download ZIP
. It is recommended to use a Python virtual environment (like venv) so that all modules and dependencies can be housed neatly in one place. -
Open your terminal and
cd
to the repository directory and run the following command:pip install -r requirements.txt
This will install all necessary modules.
Alternatively, you can choose to individually install them via
pip
calls:- Eel -
pip install eel
- Canvas API -
pip install canvasapi
- Eel -
In order for the tool to interact with the Canvas API, it needs an access-token. You're able to generate one for your Canvas user account by following the instructions elucidated in this article - How do I manage API access tokens as an admin?
Once generated, create a file named key
in the same directory as the project files. Afterwards, add a line to the file like the one below:
prod_prod: yoUrAcCesstokeNgoEsHere
Here, "prod_prod" is a key that represents your Canvas instance (you can name this key anything you want, but needs to be consistent everywhere). Then, after the colon is where you paste your access-token.
You can also add a next line afterwards to denote which subaccount you have admin access to that you'd like to visualise. This would look something like this:
prod_prod_root: 56
Here, 56 is the subaccount ID. You're able to find this by accessing the subaccount via Canvas and inspecting the URL. It should be the number at the end:
yourcanvasinstance.com/accounts/56
Note
Please note, if you don't set the subaccount in the key file, it will be set to 1 by default, which is the root account.
-
Open
main.py
. -
Look for the
ROOT_URL_MAP
dictionary. Here, add the same key that you used in the key file (e.g, prod_prod), and set its value to the URL of your Canvas instance:
ROOT_URL_MAP = {
'prod_prod': 'mycanvasurl.com'
}
- Locate the
CURRENT_ENV
variable and set it's value to the key denoting your Canvas instance:
CURRENT_ENV = prod_prod
After all the aforementioned setup is completed, to run the application, open a terminal, cd
to the correct directory and run the following command:
python3 main.py
Depending on your system, you may need to use python
or python3
in the above command.
This will launch the dashboard.
While this project does not make use of a third-party PDF library to export PDF copies or prints of the generated graphs, a print template has been provided within the print_template
folder so that the browser's print function can be utilised to create a PDF.
-
Use the tool to copy the JSON data (by clicking the
Export JSON
button) for the graph that you wish to export as PDF: -
In the
print_template
folder, opendata.js
and then paste the JSON afterconst data =
:const data = paste_your_json_here
-
Open the
print_template.html
file in your browser. This should give you a static version of the graph: -
Use the browser's print function (usually
File > Print
) toSave as PDF
.
Python dependencies:
Frontend dependencies:
- Bootsrap 4.6.2 is being used via the CDN (you're able to find the corresponding stylesheet and script tages in
index.html
). - D3.JS is being used via the CDN https://cdn.jsdelivr.net/npm/d3@7