vignettes/d-hosting-experiments-online.Rmd
d-hosting-experiments-online.Rmd
psychTestR experiments can be hosted online using the open-source ‘Shiny Server’ software. This software can be installed on a Linux server. The following instructions detail how you can provision your own server if you don’t already have one.
Note: Anthony Chmiel has very kindly put together a much more detailed guide that is available here. You are highly recommended to refer to this guide when setting up your own server.
Shiny Server hosts Shiny apps so that they can be accessed over the Internet. psychTestR delivers experiments as Shiny apps, and therefore needs Shiny Server for deploying experiments online.
Shiny Server has a free open source version and a paid professional version. While the professional version comes with useful features, in particular sophisticated load management, it seems to be prohibitively expensive for research purposes. We’ve used the open source version in our own work, and have had no problems.
Shiny Server requires a Linux server. There are various ways of obtaining your own server. Cloud-based providers, such as Amazon Web Services (AWS), provide a useful way of getting your own virtual server instead of having to buy and maintain physical hardware. The instructions below correspond to AWS because this is where our experience lies, but there are many competing cloud providers that could equivalently be used.
The overview of this stage is as follows:
t2.micro
should be sufficient
for installation and development purposes, the server can be temporarily
upgraded to larger sizes (e.g. t2.medium
) during data
collection).Instructions covering both of these steps can be found here: https://aws.amazon.com/blogs/big-data/running-r-on-aws/. This link provides some additional functionality that you may not need, such as setting up a web-hosted instance of RStudio, and integrating the server with S3. However, it also provides a CloudFormation template that automates the setup of this configuration, so it still might save you time.
The following instructions may also be useful:
By default, Shiny Server runs on port 3838. We’ve found this problematic when testing participants in schools, because some firewalls block this port. We therefore recommend running Shiny Server on port 80. You can achieve this as follows:
sudo nano /etc/shiny-server/shiny-server.conf
.listen 3838;
with
listen 80;
.sudo restart shiny-server
.You can install psychTestR on your server as follows:
sudo R
if (!require(devtools)) install.packages("devtools")
devtools::install_github("pmcharrison/psychTestR")
Shiny defaults to sanitised error messages, which is often not desirable. We recommend disabling error sanitisation as follows:
sudo nano /etc/shiny-server/shiny-server.conf
.sanitize_errors off;
in the obvious
place.nano
.sudo restart shiny-server
.options(shiny.error = browser)
so you can inspect the stack
when an error occurs.sudo R
), and then running the same commands as
you would on your local machine
(e.g. install.packages("car")
).Your experiment’s source code should already be in the form of a
directory containing the file app.R
, which should contain
the logic for defining your experiment. You should upload this directory
to the directory /srv/shiny-server/
. Our recommended
approach is currently as follows:
cd /srv/shiny-server
sudo git clone https://user@bitbucket.org/user/repo.git
(see your Git host for exact details)mv old_name new_name
.sudo chown -R shiny app_folder_name
to give the Shiny
process write permission.http://www.your-server.org:3838/app_name
, or if you changed
the port to 80, http://www.your-server.org/app_name
.