Issue converting my Psychopy code component (that runs well locally) so that it is compatible online

I have an experiment that runs very well locally, however when I tried to push it to pavlovia I got the error where it says “intialising experiment” but never continues onto the experiment. I looked the problem up in the discource and found that my experiment uses a lot of code that is not compatible with online experiments (including pandas, etc.) I was wondering if there is any way for me to make this code compatible online. Thank you so much!

Here is an example of my code that is in the code component:

import pandas as pd
from psychopy import data
import os
import json
import random

Read Excel File

file_path = ‘resources/scramble_words_1.xlsx’
df = pd.read_excel(file_path)

Shuffle only ‘facts’ column while keeping ‘scramble’ and ‘unscramble’ columns intact

shuffled_facts = df[‘facts’].sample(frac=1).reset_index(drop=True)
df[‘facts’] = shuffled_facts

Shuffle the rows of the DataFrame to maintain the correspondence between columns

shuffled_indices = list(df.index)
df = df.iloc[shuffled_indices].reset_index(drop=True)

conditions_list = df.to_dict(orient=‘records’)

#links to loop called trial_2
trials_2 = data.TrialHandler(nReps=len(conditions_list), method=‘random’, seed=None, dataTypes=[‘scramble’, ‘unscramble’, ‘facts’], trialList=conditions_list)

Hi, libraries like pandas and os are currently not in PsychoJS and it also seems like you’re building your task in Coder view? We usually recommend building your task in Builder View if you want your task to be synced online as this will minimise errors.

I’ve created a minimal demo here that should do what you’re trying to achieve and without further context of your task, the randomisation is currently being presented as text components. I’ve also synced this to Pavlovia and it is working online
demo.psyexp (21.6 KB)
conds.xlsx (8.5 KB)

1 Like

That worked great! Thank you!