Wakefield's Daily Tips

How to use the Pavlovia Shelf

If you want to store and reuse information during a single session, you should just use a variable (such as a list or dictionary). On the other hand, if you want to store information for future sessions (either by the same participant in a longitudinal study or different participants) then the solution online is to use the Pavlovia Shelf.

The Shelf is not designed for real-time interactions between participants so it should not be used accessed within an Each Frame tab or within a loop.

To use the Shelf, first go to the Shelf tab on Pavlovia and click on Add record.

A new record will appear at the bottom of the list ready to be created

image

The name of the record goes in “key components”. Scope can either be Designer (if you want the entry to be accessible by multiple experiments) or Experiment.

Type can be Integer, Boolean, Dictionary, List, Text or Counterbalance. I’ll come back to Counterbalance in a future tip, but for other uses I find that Dictionary is the most flexible.

Since the Shelf only works online I use JavaScript code components to work with it.

Dictionaries

// Store the field names in the Shelf entry in a list
fieldNames = await psychoJS.shelf.getDictionaryFieldNames({key: ["shelfName"]});
// Retrieve the value of a dictionary field in a Shelf entry
fieldValue = await psychoJS.shelf.getDictionaryFieldValue({key: ["shelfName"], fieldName:"fieldName", defaultValue:"fieldName not found"});
// Update the value of a dictionary field in a Shelf entry
await psychoJS.shelf.setDictionaryFieldValue({key: ["shelfName"], fieldName: "fieldName", fieldValue :newFieldValue});

Lists

// Set the value of a list Shelf entry
list = await psychoJS.shelf.getListValue({key: ["shelfName"]});
// Replace a list Shelf entry
await psychoJS.shelf.setListValue({key: ["shelfName"], value: newList})
// Append to a list Shelf entry
await psychoJS.shelf.appendListValue({key: ["shelfName"], elements: extraListValue})
// Pop from a list Shelf entry
finalListValue = await psychoJS.shelf.popListValue({key: ["shelfName"]})

If you are working with a Shelf entry with designer scope instead of experiment, then the key value should be changed to key: ["shelfName", "@designer"] (use @designer literally, rather than replacing designer with your Pavlovia username).

“fieldName” can be replaced with a string variable containing the field name.

Note that await means that processing will stop until the Shelf operation has finished. You can remove it if you don’t need to use the results AND you aren’t going to access the shelf again before the operation has completed.

For more information, have a look at the documentation. Using the Shelf for Multi-session testing, Counterbalancing and more online — PsychoPy v2024.2.5