Table Of Contents

Creating a New Jupyter Notebook

Last Modified: August 15, 2019

Create a new Jupyter notebook (.ipynb) in JupyterHub to develop code for visualizing, analyzing, and processing data from your tests, measurements, assets, and more.

Before you create a Jupyter notebook, complete the following tasks.
  • Install Jupyter Notebooks for SystemLink in NI Package Manager to access predefined Jupyter notebooks that leverage SystemLink Python APIs.
  • Append /niapis/python/index.html to your NI SystemLink Web Application URL to access SystemLink's Python APIs.
  • Learn about the user interface and structure of a Jupyter notebook.
  • Install Python libraries you want to use to enhance your data analysis and processing. NI recommends using PyPi to obtain packages.
  • Learn about the built-in magic commands the IPython kernel enables.
Complete the following steps to create a Jupyter notebook.
  1. In NI SystemLink Web Application, click Jupyter.
  2. On the toolbar, click +.
  3. Under Notebook, click Python 3. A Jupyter notebook launches and starts a kernel to run Python in the notebook.
  4. Rename the notebook to describe the type of report it will execute.
  5. In a code cell, import the Python modules, libraries, and widgets you need to build your notebook and make it interactive. For example, if you want to import Pandas to build and handle dataframes and Scrapbook to execute the notebook and capture results, you need to implement the following code.
    import copy
    import datetime
    import dateutil.parser
    import pandas as pd
    import scrapbook as sb
    from dateutil import tz
  6. Use one of the SystemLink Python APIs to access the data you want to visualize, analyze, or process. For example, if you want to access data from the SystemLink Test Monitor service, your code would look like the following command:
    from systemlink.clientconfig import get_configuration
    from systemlink.clients.nitestmonitor import *
  7. Establish a connection to your SystemLink Server. For example, if you want to connect a Test Monitor client to the server, use the following command:
    http_client_config = get_configuration(route_name='nitestmonitor')
  8. Define the parameters for the notebook so they display correctly in Test Monitor.
    1. In a code cell, define the parameters. For example, if you wanted to filter your test results to a specific time range and group them by the day your test system acquired them, your code may look like the following:
      filter = 'startedWithin <= "30.0:0:0"'
      group_by = 'Day'
    2. On the left pane, click Cell Inspector ( ) and define the parameters and their default values to the Edit Metadata code block. For example, your code may look like the following:
          "scrapbook": {
              "parameters": {
                  "filter": {
                      "startedWithin": {
                          "unit": "DAYS",
                          "value": 30
                  "group_by": "Day"
          "systemlink": {
              "available_group_by": [
                  "Test Program",
              "namespaces": [
          "tags": [
  9. Query a SystemLink data service for the data you want visualize, analyze, or process. For example, if you want to query the Test Monitor service for test results in ascending order, your code would look like the following:
    filter = 'startedWithin <= "30.0:0:0"'
    results_api = ResultsApi(api_client=ApiClient(http_client_config))
    query = ResultsAdvancedQuery(filter=filter, order_by=[ResultSortDefinitionObject(field=ResultField.STARTED_AT)])
    query_response = await results_api.query_results_v2(post_body=query)
    results = query_response.results
    results_list = [result.to_dict() for result in results]
  10. Format the data in a Pandas dataframe based on how you want to group the data returned from the query. For example, if you want to group your test results by their status, your code may look like the following:
    group_names = []
    for result in results_list:
        if grouping in result:
    formatted_results = {
        'id': [result['id'] for result in results_list],
        'status': [result['status']['status_type'] for result in results_list],
        grouping: group_names
    df_results = pd.DataFrame.from_dict(formatted_results)
  11. Configure how you want to visualize, analyze, or process the data. The following examples are some of the ways you can configure the data.
    • Filter out results you do not want to include in the report.
    • Convert timestamps.
    • Compute data within a timeframe.
    • Group data in a specific way.
  12. Convert the Pandas dataframe into the SystemLink reports output format. For example, coding the dataframe should look something like the following:
    [{'plot_style': 'BAR',
      'data_format': 'XY',
      'data_frame': {'data': [[0], [100]]}},
  13. Record results with Scrapbook. Refer to the following code example for optimal parsing in the NI SystemLink Web Application.
    sb.glue('title', 'Your Title Here {}'.format(group_by))
    sb.glue('axis_labels', [group_by, 'Your Title Here'])
    sb.glue('tick_labels', ticks)
    sb.glue('orientation', 'VERTICAL')
    sb.glue('result_type', 'DEFAULT')
    sb.glue('result', result)
  14. Add a new cell in the notebook.
  15. On the toolbar, select Code»Markdown to add documentation about your code to the notebook.
  16. On the menu bar, select Run»All Cells to verify the notebook returns results or processes data as expected.
  17. If the notebook returns an error, add import pdb; pdb.set_trace() to the code cell with the error to use the built-in Python debugger.
  18. Click Save.
  19. Optional: If you want the notebook to execute on a recurring basis, create a scheduled task with the Windows Task Scheduler. Refer to Task Scheduler documentation for more information.
After you create your notebook, you can bind it as a data source to a tile and monitor the results on a dashboard. If you need to share your notebook, refer to Sharing a Jupyter Notebook for more information.

Recently Viewed Topics