Deploying R shiny app as a standalone application

RShiny

R Problem Overview


I have developed a RShiny application which I would like to share internally with my colleagues (Hosting the app on a server, is not an option at this stage).

I was exploring various options, and I came across a technique for bundling your app as a standalone desktop application, with an installer file, which you can then share & distribute. (The approach is explained here & here) This is quite neat, because the users installing it need not have R (and any other required packages) to install and run the app (it has portable versions of R, chrome etc)

I was able to follow the approach and create a standalone desktop application, with an installer file, which I can now start sharing.

However, this is my concern: Ideally, I would not want my users to be able to access the source code. Is there a way to restrict such access? In the tutorial (the first link that I posted), this is what the author says:

> Lastly, keep in mind that your source code is easily accessible. If > this is a concern for you (e.g. if you are distributing to a client > that should not have access to the code) the best you can do is impede > access by first compiling the sensitive source code into a binary > package. That said, any user who knows R (and has sufficient intent) > can simply dump the code to the console.

Are there better, more fool-proof ways to impede access?

Thanks!

R Solutions


Solution 1 - R

There is now a way to turn a Shiny app into a standalone Electron app (which is a desktop app, used for apps like Slack). To find out more, see this excellent presentation (YouTube) from useR 2018, which contains further links:

Solution 2 - R

I'm not sure if it would be a great fit on the code obscurity question, but the RInno package is designed to help with the data security problem, i.e. when a company does not want to share their data with a third party. It also automates the process you referenced above and allows you to connect your app to GitHub/Bitbucket to push out updates to locally installed shiny apps via API calls on startup.

To get started:

install.packages("RInno")
require(RInno)
RInno::install_inno()

Then you just need to call two functions to create an installation framework:

create_app(app_name = "myapp", app_dir = "path/to/myapp")
compile_iss()

If you would like to include R for your co-workers who don't have it installed, add include_R = TRUE to create_app:

create_app(app_name = "myapp", app_dir = "path/to/myapp", include_R = TRUE)

It defaults to include shiny, magrittr and jsonlite, so if you are using other packages like ggplot2 or plotly, just add them to the pkgs argument. You can also include GitHub packages to the remotes argument:

create_app(
    app_name = "myapp", 
    app_dir  = "path/to/myapp"
    pkgs     = c("shiny", "jsonlite", "magrittr", "plotly", "ggplot2"),
    remotes  = c("talgalili/installr", "daattali/shinyjs"))

If you are interested in other features, check out FI Labs - RInno. If you'd like a guide on how to connect it to GitHub/Bitbucket check out the Continuous Installation guide :).

Solution 3 - R

You might be interested in DesktopDeployR, a framework for deploying self-contained R-based applications to the desktop.

https://github.com/wleepang/DesktopDeployR

Solution 4 - R

I'm not familiar with that approach, is it common? I personally haven't ever seen it. It looks like essentially what you're doing is bundling R, Shiny, a web browser, and your code, into a file. It's as if the client installs R, Chrome, shiny, and runs your code, but he just does it all in one click. You're literally giving the user your code. I don't know how it works, but if the author himself claimed that the client will be able to see the source code, then that makes sense to me and I don't think you can avoid that.

Why not just host the file on a shiny server or shinyapps.io? The client won't see your code then. Also, is it really that important that they can't see your code? A lot of times people are afraid of others seeing their code but in reality nobody really cares to look at others people's code and steal it. Unless you have some very proprietary and advanced patented code.

Solution 5 - R

You can also run your shiny app from a ".bat" executable file with code that runs your app from the command line. Just open a txt editor and add the following line:

R -e "shiny::runApp('app.R',launch.browser=TRUE) 

You can save it as, for example "test.bat". Rename app.R to whatever your shiny app name is. Make sure you have the launch browser set to TRUE, otherwise the app will only be "listening".

If you want to make sure any Rmd reporting works smoothly, also add the pandoc path to the code of your shiny app. For example add the line:

Sys.setenv(RSTUDIO_PANDOC="C:/Program Files/RStudio/bin/pandoc") 

You can get your pandoc path by running: rmarkdown::find_pandoc()

Also make sure R is in your path environment (e.g. add "C:\Program Files\R\R-4.1.0\bin" to your path environment)

Users will have access to your source code if they really want to and R needs to be installed on the PC that runs the bat file, but it might be a nice way to quickly deploy a shinyapp, for instance, for small teams that have a shared workstation. And you don't need to pay for or install a server.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDataminerView Question on Stackoverflow
Solution 1 - Rp0bsView Answer on Stackoverflow
Solution 2 - RJonathan HillView Answer on Stackoverflow
Solution 3 - RLucView Answer on Stackoverflow
Solution 4 - RDeanAttaliView Answer on Stackoverflow
Solution 5 - RMarc WarmoesView Answer on Stackoverflow