# experiments in R

## Programming Psychology Experiments in R with jaysire (and how to host it on your own server)

I got really excited when I watched this video where Danielle Navarro was describing the jaysire (j-psy-r) package she wrote for creating psychological experiments in R. This is a real gap in the space of “things that R can do really well”, plus I really don’t want to have to learn how to code in Javascript AND don’t want to pay Gorilla.sc $each time I download a participant’s data AND just want to do anything and everything from the comforts of R. The reference manual and tutorials are really well-written, so despite the title this blog post isn’t going to focus on how to use the package. Rather, the aim is to provide walkthrough the steps I took to get an experiment hosted on a cloud provider, and how to make sure that the data is saved. I needed to write this out because I will forget the steps if I don’t. ### Get your webserver up and running. My cloud provider of choice is Linode (you can check them out here and full disclaimer this is my personal referral token). Learnlinux.tv has a great set of Youtube videos that I followed to get it up and running. Here is what I did: 1. Get a linode running (I went with the cheapest$5 option and Ubuntu LTS 20.04).
3. Connected my domain name to the server (this can take up to a day as it depends on when the records get updated).
4. Enabled https with a SSL certificate from certbot (especially important if you are intending to run participants).

It sounds like a lot but it is just the first 5 videos of this playlist.

### Get the server ready for deployment of jaysire experiments

#### 1. Install apache and php

SSH into your server and run the following:

sudo apt install apache2 php

Before you run the run_webserver() function to deploy your experiment that you have created using jaysire, you’ll need to do two things. (I only found this out after quite a lot of time!)

The run_webserver() function requires that the limited user has the ability to write files into the /var/www/html folder. Change the $USER to your username. sudo chown$USER:www-data /var/www/html
sudo chmod g+s /var/www/html
sudo chmod o-rwx /var/www/html

With credit to this Stack Exchange answer. I didn’t need to edit the configuration files on Apache as the default was just fine.

#### 3. Set up the /var/www/server_data folder on your server.

You need a folder on the server where the webserver has permissions to write to. By default the experiment will write the data to this folder on your server /var/www/server_data. You’ll need to set this up by typing the following commands into the terminal.

sudo mkdir /var/www/server_data
sudo chgrp www-data /var/www/server_data
sudo chmod 775 /var/www/server_data

With credit to this (Github issue](https://github.com/djnavarro/jaysire/issues/8).

### Deployment!

Run this in your R console:

run_webserver(
experiment_folder = "experiment", # rename accordingly
keyfile = "~/.ssh/id_rsa",
webserver_configured = TRUE
)

Note that this assumes that the ssh key that you’ve connected your server to in Step 1 is id_rsa (if you’ve followed the learnlinux.tv tutorial this would be correct).