Deploy a jspsych experiment locally

run_locally(
  path,
  experiment_folder = "experiment",
  data_folder = "data",
  port = 8000
)

Arguments

path

Path where the experiment is deployed

experiment_folder

Experiment subfolder

data_folder

Data subfolder

port

The port to use

Details

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