Skip to main content

Module to display dynamic quizzes in Jupyter notebooks and Jupyter Books. Uses JavaScript to provide

Project description

JupyterCards

JupyterCards is a tool for displaying interactive flash cards in Jupyter notebooks and Jupyter Book. JupyterCards was created to enable interactive quizzes for readers of my book Foundations of Data Science with Python1

I have collected all of those flashcards into a single set here: Data Science Flashcards. Or you can see them in the individual sections on the website for the book at Foundations of Data Science with Python — Online Resources.

The current version of JupyterCards uses a hack to make JupyterCards math work properly on Jupyter Lab/Notebook 4. The issue is that Jupyter 4 installs its own custom MathJax, which does not support all the methods of the full MathJax. I install the regular version of MathJax over Jupyter's custom version. I have tried to work with the Jupyter community to have them expose a method that would allow dynamic updates of displayed math code, but this has not been implemented after almost a year, so I feel I have to release this version. Please submit an issue if you encounter any problems when using Jupter Cards.

JupyterCards is part of my effort to make open source tools for developing modern, interactive textbooks.

If you would like to see a video that introduces these tools and discusses why I made them, check out my JupyterCon 2023 talk on Tools for Interactive Education Experiences in Jupyter Notebooks and Jupyter Books.

Here is an animated GIF showing JupyterCards in action:

Animated GIF showing the output of JupyterCards for a sample set of 3 cards

Flash card content can be loaded from:

  • a Python list of dict,
  • a JSON local file,
  • via a URL to a JSON file.

As of version 1.7, JupyterCards supports switching cards by swiping left on touch devices.

Tracking Known and Unknown Cards

As of version 3.1, JupyterCards will default to showing checkmark and x-mark widgets that can be used to track which cards you already know. This can be turned off by passing known_widgets=False. You can add persistent storage across sessions by setting local_storage=True. The default is False. If set to True, the user will be asked one time whether they wish to store their progress in local storage. Then cards that are marked as known when be stored in the browser's persistent localStorage, and this list will be persisted across sessions.

Note: JupyterCards always requires MathJax to be loaded. If you are using JupyterBook, it may not always load MathJax if you do not have any LaTeX on your page. To resolve this, you can include the invisible math command $\,\!$ in any Markdown cell. I hope to remove this requirement in the future.

Installation

JupyterCards is available via pip:

pip install jupytercards

Usage in Python

From Python, call the display_flashcards() function. Pass it a reference to your card data file or variable (see Card Data below). Examples are shown in the provided Jupyter notebook, `example.ipynb'.

Keyboard Controls

Keyboard controls:

  • Space to flip card over
  • Enter, right arrow, or j to slide to next card

Notes:

  • In Jupyter Book, you may have to click the card to get focus before using the keyboard shortcuts.
  • In Jupyter Lab, hovering your mouse over the body of the card should be sufficient to send key presses to Jupyter Cards.
  • In both, you may need to avoid math typeset by MathJax because that can intercept key presses.
  • You may disable keyboard control using keyControl keyword parameter: display_flashcards(ref, keyControl = False).
  • If you test the keyboard controls, please add your feedback to the related Issue, or email me/tweet at me.

Card Data

Jupyter Cards is designed to load card data from a remote or local JSON file; card data may also be loaded directly from a Python variable -- see more further below.

The JSON file should contain a single JSON array of JSON objects. Each JSON object must have the following two keys:

  • "front": a string containing the text to be shown on the front of the card
  • "back": a string containing the text to be shown on the back of the card

In addition, each JSON object may have the following optional key:

  • "topic": a string that identifies a topic that can be used to choose a subset of cards in a file

Although using JSON objects for each flashcard is overkill, this model was chosen to support future extensions to this library.

Cards can also be specified as a Python list of dictionaries with the same keys.

JupyterLite

As of version 2.5.0, JupyterCards should work on JupyterLite after loading the modulue via micropip:

import micropip
await micropip.install('jupytercards')
                       
from jupytercards import display_flashcards
github='https://raw.githubusercontent.com/jmshea/foundations-of-data-science-with-python/main/04-probability1/flashcards/'
display_flashcards(github+'outcomes-samplespaces-events.json')

Making flashcards in Markdown

As of version 1.9.0, I have added helper functions to convert flashcards created in Markdown to the JSON format that JupyterCards expects. In its simplest version, just put the front text in a Markdown heading (line starting with #) and put the back text below. See (Markdown-flashcards.ipynb) for more discussion and examples of how to use this functionality.

Example of generating flashcard files from JupyterBook notebooks

In my Jupyter notebooks that are used as input to JupyterBook, I use panels with the heading "DEFINITION" to call out definitions in the text. I have provided a helper program extractdefinitions.py that I use to scan files for the DEFINITION header and extract the appropriate lines that follow. The resulting terms and definitions are dumped to corresponding JSON files in a "flashcards" directory. An additional JSON file is generated for the whole chapter. extractdefinitions.py takes 2 arguments: the directory to parse and the chapter number to use to label the overall JSON definitions file. This program is very specific to my workflow and I am offering it only as reference in case it can help someone else with a similar situation.

1 Affiliate link. As an Amazon Associate I earn from qualifying purchases.

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

jupytercards-3.2.1.tar.gz (991.7 kB view details)

Uploaded Source

Built Distribution

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

jupytercards-3.2.1-py2.py3-none-any.whl (19.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file jupytercards-3.2.1.tar.gz.

File metadata

  • Download URL: jupytercards-3.2.1.tar.gz
  • Upload date:
  • Size: 991.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for jupytercards-3.2.1.tar.gz
Algorithm Hash digest
SHA256 d6b751799d106f83ffc1f58a378f9df79e286dbae5ffe0a6e50e876d247bdb11
MD5 134740718d9492e7a1425b5035f65310
BLAKE2b-256 d83aae729cd84d10618a3b6946c856980b6c93cc7d40c5eed5d5e00a2d820270

See more details on using hashes here.

File details

Details for the file jupytercards-3.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jupytercards-3.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8f37c535c69fe5c316ce47fcf730f17bfa93b67e617ca1d680b681c9256cb0fe
MD5 594a96297f92185ea48c551edd438dfb
BLAKE2b-256 89b504acaf7971bf5262ab7ee2916c89c2c374f3ea2eeb5a8d877b984604df9a

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