62

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!

Dataminer
  • 1,499
  • 3
  • 16
  • 21

5 Answers5

36

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:

zx8754
  • 52,746
  • 12
  • 114
  • 209
p0bs
  • 1,004
  • 2
  • 15
  • 22
11

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 :).

Jonathan Hill
  • 1,745
  • 15
  • 25
  • 1
    `install_inno()` is a hindrance as executable download is not permitted to me due to data security. Can you suggest a workaround? – Divi May 23 '17 at 20:06
  • Sure! You will have to get someone with permission to install Inno Setup - http://www.jrsoftware.org/isdl.php. The RInno package requires Inno Setup to build installers for your Shiny apps. – Jonathan Hill May 23 '17 at 20:08
  • 1
    Also worth mentioning, this works only for Windows – Claudio Paladini Jan 07 '21 at 08:49
  • @ClaudioPaladini Have you created installer for you Shiny apps. As, I'm figuring out a way right now – Golem Aug 07 '23 at 22:59
8

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

https://github.com/wleepang/DesktopDeployR

Luc
  • 899
  • 11
  • 26
  • 1
    This package relies on installing R-Portable, which is Windows only. README.md does say that "the framework can be used with [...] a system installed version of R", which I assume would allow for cross-platform building, but there are no further instructions on how to do it. – Waldir Leoncio Jan 28 '22 at 10:20
4

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.

DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • 1
    Thanks for your comments! I did think about shinyapps.io..And may be I will explore it further. But my worry was cost (to some extent) and more importantly, the data privacy part (given that the data being used by the app is fairly sensitive). And the organization that I work for, has some fairly stringent guidelines around data privacy and related issues. So I may run into some road blocks there. Secondly, it's not terribly important that users shouldn't see the code..So if there is no easy way to mask the code, I will end up just shipping out the whole package. – Dataminer Nov 04 '15 at 04:52
  • Cost is free if you're not using it tooo much. If you're worried about cost and privacy, then [use your own shiny server](http://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/). This way it's still hosted by you and you control it. I guess it depends if you want the app to be completely shipped to the client or if you want to host it. It it is given to them as a standalone, it means you can't update it and fix bugs. – DeanAttali Nov 04 '15 at 07:35
0

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.