-
Notifications
You must be signed in to change notification settings - Fork 2
Using Shiny Server
The shiny server doesn't have any R libraries installed (for more informations,
see the packages.txt file). The only way to use specific libraries in shiny applications
is to manage them using packrat. packrat
is a project able to manage package dependencies in isolated environment. A project
using packrat
is able to manage package version independently from the main or
global R instance. In such way, we can deal with complex dependencies in each project,
avoiding dependencies and version issues that could rise up when dealing with
different library requirements. Moreover, we can add a new shiny application to
our shiny-server
without installing dependencies in the shiny
docker image.
The easiest way to import a shiny project into shiny-server
is to start a new
shiny project in Rstudio and enable the packrat
option during project creation:
Packrat can track the downloaded package (*.tar.gz
) in our project. In order to
save space we can configure packrat to ignore package sources:
After that, you can install (and remove) required packages with the install.package
command as usual: every downloaded package will be installed in the project directory
instead of the deafault R library path.
In order to track your project packages, and reinstall the same packages version
in our shiny-server
, we need to do a snapshot of our packages in R terminal with:
> packrat::snapshot()
This command will track all our dependencies in the packrat
local database. This
database should be tracked with repository in order to install the same package
versions in our shiny-server (or to be portable and reproducible in general by other users).
Remember to call packrat::snapshot()
every time you need to add / remove a R
package in your project, in order to track the latest library changes.
For more informations on packrat
, please see the official site
or follow the walkthrough guide.
In order to add you shiny application to shiny-server
, you need to add your project
folder into the shiny-apps
folder of the shiny-server
instance. Please remember
to use a safe-url name since the project name will be used as a location by
shiny-server
. Next, from shiny-server
project root directory, open a new terminal
using the shiny
docker container with docker-compose
:
$ docker-compose run --rm --user $(id --user):$(id --group) shiny /bin/bash
the --user $(id --user):$(id --group)
option is required to execute command as
your local user inside the docker container, instead of executing commands using
the default shiny
user (which doesn't have write permission in your project
repository, which is required to install locally your dependencies using packrat
).
Navigate to the /srv/shiny-server
folder and search for your project directory
(all project/folder inside the shiny-apps
directory will be mounted inside
/srv/shiny-server
directory in the shiny
container. See the volume option
in the docker-compose.yml file of shiny-server
project).
For example, I have cloned the PCAetude
project in my shiny-apps
directory and I need to enter into the /srv/shiny-server/PCAetude
directory inside my shiny
container. Inside the project directory (PCAetude
),
start a new R terminal and simply call
> packrat::restore()
To install all your project dependencies using the same R version used by the
shiny-server
. After that you can leave R and bash terminal by typing exit
on both terminals.
Now log-in into the django admin site and navigate to the Serve/Shiny apps
location
(http://localhost:22080/admin/serve/shinyapp/). Click on ADD SHINY APP
button
in the admin page, as shown in the following figure:
In the following form, location must start with /shiny/
and followed by your
project directory name, in my case /shiny/PCAetude
Note: the initial /shiny/ location is required by the NgINX container in order to forward client request to the shiny server. Next relases will have /shiny/ location automatically prepended to your project folder name.
Other fields are required for shiny application description. You can upload a
thumbnail to preview you application using django and set application ownership
by selecting users which can display your new shiny application. The is public
option is required if you need to show your shiny application without user login
(public application).
After saving, your new application will be part of the application list:
And could be accessed directly, using the link provided in the location field (in my example, http://localhost:22080/shiny/PCAetude/). User credentials will be evaluated by NgINX and Django: you won't be able to see a private application without logging
All shiny-server project are available under GPL version 3 license. You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.