Skip to main content

Jupyter Notebook forms using ipywidgets

Project description

nbforms

Binder

nbforms is a Python package designed to allow forms to be submitted by users such that the data they submit is immediately available for use in the notebook by the entire group. This is accomplished using ipywidgets and a Heroku-deployable Sinatra webapp, nbforms-server.

Installation

To install the Python package, use pip:

pip install nbforms

Deployment

Setup: Server

Before using nbforms in a notebook, you must deploy a webapp to Heroku which will collect and organize the responses. If you plan to have multiple notebooks, you only need one server, as you can provide a notebook identifier in the config files that will distinguish responses.

To deploy the webapp, click the deploy button in the nbforms-server README.

Setup: Config File

nbforms requires a JSON-formatted config file to set up the Notebook class. The default path that Notebook checks is ./nbforms_config.json, although you can pass a custom path to the Notebook constructor. The structure of the config file is very specific; it contains the information that the notebook needs to create widgets and send requests. The structure of this file is:

{
    "server_url": "",             # URL to your Heroku app

    "notebook": "",               # an ID to collect responses

    "questions": [{               # questions to ask, a list of dicts

      "identifier": "",           # a question identifer, should be unique within
                                  # this notebook
      "type": "",                 # question type; can be one of:
                                  #   multiplechoice, checkbox, text, paragraph

      "question": "",             # the question text

      "options": [                # options from which to choose if type is 
        ...                       # multiplechoice or checkbox
      ],
      "placeholder": ""           # placeholder for textbox if type is text or
                                  # paragraph
    }, 
    ...                           # more question dictionaries
  ]
}

The server_url key should be the URL to your Heroku-deployed nbforms-server, e.g. https://my-nbforms-server.herokuapp.com. The notebook key should be some string or number to identify the notebook that you're deploying. This is used to keep the notebook responses distinguished on the server. Finally, the questions key should be a list of dictionaries that define the information for your questions.

Questions can have one of four types: multiplechoice, checkbox, text, or paragraph. The type key in the question is used to create the widget. If you have a multiplechoice or checkbox, you must provide a list of options as the options key. For text and paragraph responses, you can provide an optional placeholder key which will replace the default placeholder.

There is a sample config file at demo/nbforms_config.json. Each nbforms-server comes with a page that will generate a config file for you. The config generator for the demo server can be found here.

In-Notebook: Import and Instantiate

To use the nbforms, you must first import it and create a Notebook instance. This will load the config file (defaulting to look at ./nbforms_config.json) and ask the user to input a username and a password. If the username already exists on the server, the password will be checked and an API key will be generated, to be stored in the Notebook class. If it does not exist, a new user will be created, and an API key generated. If the user does exist but an incorrect password is provided, the cell will error.

import nbforms
form = nbforms.Notebook()

In-Notebook: Collecting Responses

To collect the responses for a question, insert a cell that calls the Notebook.ask function on the identifier of the question. For example, if I had a question q1, I would call

form.ask("q1")

This will output the widget and a "Submit" button that, when clicked, will send an HTTP POST request to your nbforms server with the student's username, API key, notebook ID, question identifier, and response to be stored on the server.

Notebook.ask can accept multiple questions; for example, form.ask("q1", "q3") would display a widget with q1 and q3 as its tabs. Passing no arguments to Notebook.ask will display all of the questions.

In-Notebook: Retrieving Data

nbforms allows you to get your data from the server and collect it into either a datascience Table or a pandas DataFrame. To retrieve the responses from the server, use Notebook.to_table or Notebook.to_df; the optional user_hashes argument (default False) indicates whether or not to include a column with the hashes username.

# datascience Table
form.to_table("q1", "q2", ...)

# pandas DataFrame
form.to_df("q1", "q3", ..., user_hashes=True)

Database Maintenance

There is not much database maintance that can be done, but you can optionally delete all responses on the server by running rake clear on your Heroku app.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nbforms-0.1.6.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nbforms-0.1.6-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file nbforms-0.1.6.tar.gz.

File metadata

  • Download URL: nbforms-0.1.6.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for nbforms-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a808c1bc3d1b2db924a3f7eac3d78124d44bd831f12a8d54955a00547a7cc450
MD5 44b1efadada831b2274ff03fe5922ca2
BLAKE2b-256 621cdd664a16e061f9d1df89b294ab6d0cdae14ae3575cc2aa6f5f7727ec5f05

See more details on using hashes here.

File details

Details for the file nbforms-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: nbforms-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for nbforms-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 770b2c322d1fc9dc590a7d4125ae8fdb5b67d62cfa792a563be6add9850f5ace
MD5 0a51b82373a64ad411d3c7c1b6680174
BLAKE2b-256 7a4d3dd36ee5122e34eb3fa9c1a11064c933e7431718014ca0b40b034bfc5477

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page