deploying shiny app that depends on c++ library

I'm trying to use shinyapps.io to host a Shiny app I've created. I've gotten the app to run locally on my machine. It uses a c++ library that I'm calling with help from Rcpp.

Right now, I have the shinyapp directory sitting inside my larger project directory, which contains cpp code. My app.R file looks like this

library(shiny)
library(Rcpp)

Sys.setenv("PKG_LIBS"="-L/home/taylor/holdem_monte_carlo/Release/src -lhmc-lib -Wl,-rpath=/home/taylor/holdem_monte_carlo/Release/src")

Rcpp::sourceCpp("do_comps.cpp", verbose = T, rebuild=T)

ui <-  ...  
server <- ...
shinyApp(ui = ui, server = server)

Can I get terminal access to download and build c++ libraries on shinyapps.io? Then I could just keep the code as is, but change the directories. Any idea how to do that? Or are there any other ideas for how to get this to work?

I figured it out by taking the easy route. I made all the c++ files part of the project so I didn’t have to link with any externally compiled library.

1 Like

Hi,
In my case, the app depends on zintr package which is an R package hosted in github. The issue is we can not install zintr before to install zint C library as:

git clone https://github.com/zint/zint.git zint
cd zint
mkdir build
cd build
cmake ..
make
sudo make install
sudo cp /usr/local/lib/libzint.* /usr/lib

After that we can
install zintr :

devtools::install_github("CannaData/zintr")

I added the zint clone folder in /src/ at the same level then ui.R and server.R and global.R

and a executable configure file at the same level with :

# terminate on failure
set -e
set -x

if [ -x "$(command -v cmake)" ]; then

	echo "-- Trying to build zint via cmake ..."
	cd src/zint
	mkdir -p build
	cd build
  cmake ..
  make
  sudo make install
  sudo cp /usr/local/lib/libzint.* /usr/lib
  su - -c "R -e \"devtools::install_github('CannaData/zintr'))\""

else
	echo "-- cmake is not installed on this system. zint library is failed ..."
fi

Here is the log of the deployment:

Preparing to deploy application...DONE
Uploading bundle for application: 4295906...DONE
Deploying bundle: 4739195 for application: 4295906 ...
Waiting for task: 956504412
  building: Parsing manifest
  building: Building image: 5436894
  building: Fetching packages
  building: Building package: zintr
################################ Begin Task Log ################################ 
[2021-06-21T12:45:46.195076984+0000] Installing R package: rlang (0.4.11)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘rlang’ ...
* DONE (rlang)
[2021-06-21T12:45:46.461611201+0000] Installing R package: viridisLite (0.4.0)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘viridisLite’ ...
* DONE (viridisLite)
[2021-06-21T12:45:46.681194765+0000] Installing R package: sourcetools (0.1.7)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘sourcetools’ ...
* DONE (sourcetools)
[2021-06-21T12:45:46.908460054+0000] Installing R package: rematch (1.0.1)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘rematch’ ...
* DONE (rematch)
[2021-06-21T12:45:47.085921837+0000] Installing R package: sys (3.4)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘sys’ ...
* DONE (sys)
[2021-06-21T12:45:47.266294419+0000] Installing R package: fansi (0.4.2)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘fansi’ ...
* DONE (fansi)
[2021-06-21T12:45:47.467402895+0000] Installing R package: utf8 (1.2.1)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘utf8’ ...
* DONE (utf8)
[2021-06-21T12:45:47.670406229+0000] Installing R package: assertthat (0.2.1)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘assertthat’ ...
* DONE (assertthat)
[2021-06-21T12:45:47.841341005+0000] Installing R package: cpp11 (0.2.7)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘cpp11’ ...
* DONE (cpp11)
[2021-06-21T12:45:48.059464814+0000] Installing R package: commonmark (1.7)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘commonmark’ ...
* DONE (commonmark)
[2021-06-21T12:45:48.286192427+0000] Installing R package: curl (4.3.1)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘curl’ ...
* DONE (curl)
[2021-06-21T12:45:48.550362486+0000] Installing R package: isoband (0.2.4)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘isoband’ ...
* DONE (isoband)
[2021-06-21T12:45:49.140370705+0000] Installing R package: xtable (1.8-4)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘xtable’ ...
* DONE (xtable)
[2021-06-21T12:45:49.350797777+0000] Installing R package: clipr (0.7.1)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘clipr’ ...
* DONE (clipr)
[2021-06-21T12:45:49.528563749+0000] Installing R package: magrittr (2.0.1)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘magrittr’ ...
* DONE (magrittr)
[2021-06-21T12:45:49.728431099+0000] Installing R package: colorspace (2.0-1)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘colorspace’ ...
* DONE (colorspace)
[2021-06-21T12:45:50.113402948+0000] Installing R package: rappdirs (0.3.3)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘rappdirs’ ...
* DONE (rappdirs)
[2021-06-21T12:45:50.290324666+0000] Installing R package: plogr (0.2.0)
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *binary* package ‘plogr’ ...
* DONE (plogr)
[2021-06-21T12:45:50.471386440+0000] Building R package: zintr (1.0)
/mnt/packages/build /mnt
Warning in untar2(tarfile, files, list, exdir, restore_times) :
  skipping pax global extended headers
* installing to library ‘/opt/R/4.1.0/lib/R/library’
* installing *source* package ‘zintr’ ...
** using staged installation
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing ‘/opt/R/4.1.0/lib/R/library/zintr’
################################# End Task Log ################################# 
Erreur : Unhandled Exception: Child Task 956504424 failed: Error building image: Error building zintr (1.0). Build exited with non-zero status: 1
Exécution arrêtée

Thanks