Deploy a jspsych experiment locally

  experiment_folder = "experiment",
  data_folder = "data",
  port = 8000



Path where the experiment is deployed


Experiment subfolder


Data subfolder


The port to use


The purpose of the run_locally() function is to start an R server running (using the plumber package) that will serve the experiment from the local machine. The path, experiment_folder and data_folder arguments specify the location specify where the experiment should be deployed, and should be the same that was used when calling build_experiment()) to build the experiment originally. The port is the numeric value of the port on which the experiment is served. Once run_locally() has been called, a browser window should open showing the relevant page.

There are two reasons to deploy a local experiment using run_locally() rather than simply opening the relevant "index.html" file in the browser. The first is for the purpose of saving data. For security reasons, browsers do not generally permit client-side javascript (e.g., the code that runs the jsPsych experiment) to save files to arbitrary locations. For this reason writing the data to file is the job of the R server, not the javascript code that is running through the browser. In other words, if the experiment is deployed locally using the run_locally() function, then the save_locally() function that used to record data locally will work properly. If, however, the "index.html" file is opened without starting the R server, data will not be saved to file.

The second reason for using run_locally() is that it opens up the possibility that an experiment could use server-side R code at runtime. At the moment jaysire does not have any functionality to do so, but in principle there is nothing preventing the R server from playing a more active role when the experiment is running, and future versions of the package may develop this functionality further.

See also