psychopy.org | Reference | Downloads | Github

Experiment that works in builder throws variable ReferenceError after Pavlovia Upload

#1

URL of experiment: https://pavlovia.org/run/djwyen/language-learning/html/

Description of the problem:
Hello all,

We are working on a project in PsychoPy. Our project extensively uses python code, but all of it is in code components of routines in the builder (ie the experiment is fully created in PsychoPy’s builder). It runs perfectly fine in the desktop version, but errors crop up in the Pavlovia version. We get the error “ReferenceError: Can’t find variable: selection_example”

With the way our experiment is set up, there is a code component in a routine at the beginning of the experiment which uses pandas to import data from an excel file to a DataFrame. We access data in the DataFrame to create a string called ‘selection_example’ which we pass to the ‘Selected rows’ parameter of a loop in our experiment.

Since the routine that defines ‘selection_example’ chronologically precedes the loop in our experiment’s flow, shouldn’t the variable ‘selection_example’ be defined by the time PsychoPy reaches the loop that uses it? It seems that something changes during the process of the upload from Python to JavaScript — does anyone know how we can address this?

Thanks!

#2

Python won’t run online: any custom code needs to be translated to JavaScript. Builder does this automatically for code it generates itself, but you will need to manually translate all of your custom code. Code components allow for both languages to be shown side-by-side to facilitate the translation process.

So you are going to need to find a JavaScript equivalent to the importing done by the Python pandas library. Your life will probably be simpler if you shift to using a simpler text format (like .csv) rather than a native .xlsx file.

You also then aren’t going to have access to the pandas data frame Python class. I don’t know if there is an equivalent in the JavaScript world, or if you should look at using other native data structures.

#3

Thanks for the prompt reply! Could you clarify what you mean by “code components allow for both languages to be shown side-by-side?”

#4

Look at the pop-up menu button that specifies the language of the component: Python, JavaScript, or both.