Running Coded Experiments Online

I have seen a number of posts about this and wanted to follow up on the best approach at this point. I have an experiment that I coded up in Psychopy (created with just code, not using the GUI). I would like to get it to run online, using Pavlovia, but I do not know Javascript. I was wondering if there is a protocol for the best approach to use to get it running online. I am considering re-creating the experiment using the GUI, but was wondering if there is a better approach.

The alternative is to write the entire experiment in Javascript. It will almost certainly be easier for you to use Builder to take care of nearly all of that for you, so you only need to provide snippets of Javascript via code components, if required for any non-standard capability.

Makes sense. Thank you for your input!

Do you need to code it from scratch in the builder? or there is a way to upload it from python?

Yes you do need to code it from scratch but that could involve pasting large chunks of your existing code into code components.

thank you! how do i enter these code components? and how do i know which i can just copy?

Sorry – I assumed that you knew how to use Builder (select a code component from the right hand side). The bits you’ll be copying will depend on your experiment and your Python knowledge. You could try pasting just about everything into a single code component and see how you get on.

ok thank you. i will try it. i just found it easier to code in python than on the builder.
and if everything works good on the builder, I will be able to upload it with no problem online?

Perhaps another good place to start would be to make a very very simple experiment in Builder (e.g. displaying one piece of text) and check the code for that to find out what code Builder adds to every experiment. Then you could delete similar code from your script before pasting into Builder.

i will try it. thank you very much!

I am having a similar question/issue. I programmed my entire experiment in the builder but I needed to change only 4 lines of code afterwards (once I created the script) to make it work (these four lines randomise the stimuli that I couldn’t randomise properly in the .xlsx file). But, how do I to get it to run online?

  1. Can I copy only the modified script to pavlovia to make it work?
  2. On the website it says it cannot read .xlsx file and I seem to get an error when trying to use the html function. When I convert to a csv file, the experiment only works halfway as it doesn’t show the images that are defined in the experiment file.
  3. I am wondering whether to “translate” the whole caboodle to javascript but since I have 0 experience with it I am wondering if there is a simpler solution.

Thanks in advance,

Go back to your Builder version.

Add the four lines of code into a code component which should auto translate to JS

Check my crib sheet for things in your four lines which might not translate correctly without help (e.g. random)

Do not attempt to do your own full translation to JS unless you are an experienced JS programmer.

But writing an experiment in JavaScript is quite different from Python. JavaScript does not necessarily get executed sequentially because it is designed to work with webpage loading, where things can happen in parallel while waiting for resources to load. So let Builder do the heavy lifting for you in terms of generating the script. The learning curve for Builder will be much easier than learning what is needed to script a JavaScript experiment entirely manually. Adding a few lines of JavaScript here and there via Builder code components is generally straightforward though, as it is for Python (particularly if referring to Wakefield’s crib sheet).

Thank you very much. I just hope the Builder can do all I need for my experiment. It was easy for me to program it in Python and I find it difficult in the Builder.

thanks for your suggestion. The experiment runs fine locally but never goes beyond the ‘initialising experiment’ phase online. A couple of things I noticed. When I press the export html, it only creates an index but NO HTML folder when synching. So I set up everything as suggested with an HTML folder, a resources folder the condition file within the resources folder and then synched the whole thing. But, sadly, this didn’t help. I checked the crib sheet but a lot of it is rather abstract to me to be frank. I pasted most of the recommend code into the begin experiment code. With some of the stuff I was a bit lost as to what to do with it.

There is an experiment already that works online (glasgowfacematchingtask) since I am presenting one image at a time and people have to press one of two buttons on the keyboard. That’s it. So I tried to view the .js code in the hope of adapting their script but this didn’t work either as I couldn’t view this file and their original psyexp file looks pretty much like mine. I wish I could adapt this working task but without being able to see which exact snippets of code need to be modified, I am not quite sure where to go from here. I also don’t know if it doesn’t run because the html conversion fails or doesn’t function as described in the documentation. Any suggestions?

PS: the parts of the cribb sheet I was a bit lost what to do with where

  1. myData = new TrialHandler({
    psychoJS: psychoJS,
    nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
    extraInfo: expInfo, originPath: undefined,
    trialList: ‘recall.xlsx’,
    seed: undefined, name: ‘myData’});
  2. which exact object (image) should I define at the beginning of the experiment? All individual images? A placeholder variable for an image? I placed the setautodraw true/false at beginning and end of routine.


newer versions of PsychoPy do not create a html-folder. PsychoPy should create the needed JavaScript and html-files when syncing to a project.

If your experiment does not go

it might be better to open a new thread describing the error and giving access to your project to get more help. You could locate the error that prevents your experiment from going beyond ‘initalising’ by pressing F12 (in Firefox) to open the debugger. Posting the relevant line will give you more feedback than stating that your experiment does not go beyond initialising.

If there is a working example online, you could fork the project, sync the forked project to your pc, adapt it to your needs or work our the differences.

Best Jens