RShiny - How to share app within network - r

I created an R Shiny application that I'd like to share with my co-workers within my network.
I tried hosting the app on my computer so that other users from the network could access it and use it with their data files.
I tried:
runApp("appname",host="0.0.0.0",port=3986)
And also:
runApp("appname",host="DNSMachinename")
The latter attempt resulted in the following error:
While my colleagues are able to acceess the app, it doesn't really run like it does on my machine.
Thanks for the help.

Since you showed your interest in Shiny server, and it might be more convenient for me to just post a few thoughts in the "answer" since it won't fit well in the comment.
Since you have a group, and I would highly recommend you take a look at R server and shiny server.
(1) Shiny server
You can totally install Shiny server on a old computer and I would recommend using Linux OS like (Ubuntu) and it will save you some time following the tutorial. We have a cluster and we used one of the servers there to host a shiny server and shiny server at the same time. And only internal employee can access it and it is within company's network.
(2) R server
I am not exactly sure which environment you are using to program R but if you want to evangalize R in your team. Have a stable environment that could be accessed by everyone inside your company with authentication is a good way to get started.
(3) shinyapps.io
Is a free platform that you can host your shiny app, it is in alpha version and I don't think there is much authentication or security built in. HEREenter link description here is an example hosted on shinyapps.io
(4) AWS free tier
If you have never used AWS before, you can have a micro instance running on AWS free for one year! I would highly recommend using AWS instead F* around with a old computer.

If you are still trying to get buy-in for your server or cloud solution, I just finished developing the RInno package for this exact problem, i.e. when a company will not pay for Shiny Server or there are security concerns with cloud services.
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

The shiny tutorial list a number of ways to share your app. I particularly hosting a zip file somewhere with the app, and letting your co-workers use runUrl to automatically download the app and run it locally. In this way people can continue to run the latest version of the app, but it does not run on your machine.

Related

Best (standard) way to deploy the libraries for a shiny app to the shiny server?

I'm trying to get a shiny app deployed on Shiny Server. I can do that without any issues, but when trying to deploy an app that has a number of dependencies (remote and local) we keep running into issues.
We used renv to track the dependencies (on the Windows dev box) and rebuild it from scratch on the Linux prod box, but even though the dependencies are rebuilt and some get loaded, others do not. The .Rprofile of the user running the app is pointing to the renv activation script.
For the sake of clarity, we need and want all the R code to be built from the source code on the Linux box.
What is the best or standard way (or even a poor way that works) to deploy the libraries for a shiny app to the shiny server? Is renv even the right tool for this scenario or is there a better tool?
I've tried reading the shiny server documentation and the closes it only mentions that it uses the .Rprofile of the user running the app, but there doesn't seem to be any sort of guide on the best way to deploy dependent libraries.
This renv documentation discusses some reproducibility caveats:
system dependencies, and
changes in CRAN (e.g. a binary no longer being available).
Since you are moving from a Windows to a Linux system your packages may have unmet system dependencies (things that need to be installed outside of R) that you didn't encounter in Windows. For example, rJava is required for some of the Excel-related R packages, and getting its related system dependencies installed and working on Linux can sometime be a challenge. You can use the RStudio Package Manager Website to figure out what system dependencies are required for different R packages for your particular Linux OS. Also, the error messages you get when running these apps on Linux should point you in the right direction. These system dependencies are what you'll have to manage yourself since renv doesn't.
But for a more production-level solution you can try Docker and ShinyProxy. For apps with many dependencies or especially external dependencies (e.g. Python, SQL, etc.) you can guarantee more reproducibility using Docker. ShinyProxy can be used to host apps built into docker images. This is more work, but you ensure the entire system is reproducible, not just the R version and R packages. ShinyProxy also adds additional hosting capabilities like user authentication.

Package management in RStudio Connect

I have recently started using both RStudio Connect and the RStudio Package manager.
I came across this short page from RStudio that says "You can integrate RStudio Package Manager with both RStudio Server Pro and RStudio Connect for a seamless experience with your R packages.".
Is there some specific documentation or an example? I'm a bit confused about what this means and how the package manager will work with the packrat and rsconnect packages that are used when deploying applications.
If it is relevant to consider, I plan on primarily deploying shiny apps to Connect using the API with scripts similar to the ones that appear in this repo: https://github.com/rstudio/connect-api-deploy-shiny/tree/master/deploy
Just to not leave the question without answer:
For RStudio Connect it is possible to configure the settings related to RStudio Package Manager in the main config file, by default is /etc/rstudio-connect/rstudio-connect.gcfg.
Example peace of config file:
; /etc/rstudio-connect/rstudio-connect.gcfg
[RPackageRepository "CRAN"]
URL = "https://cran-mirror.production.company.com/"
[RPackageRepository "CORPORATE"]
URL = "https://corporate-packages.production.company.com/"
This will equals to following command in R:
options(
repos = c(
CRAN = "https://cran.rstudio.com/",
CORPORATE = "https://corporate-packages.development.company.com"
)
)
Source: https://docs.rstudio.com/connect/admin/appendix/configuration/#RPackageRepository
I work at RStudio and came across your post. This community is mainly for open source users, but for licensors of RStudio's professional products (like RStudio Connect, RStudio Server Pro, and Package Manager), your organization should also have a designated Customer Success Representative that can coordinate a discussion to explain these details to you. You can find the contact information here: https://rstudio.com/about/contact/
You can also file a support ticket here if you need more technical/configuration related guidance:https://support.rstudio.com/hc/en-us/requests/new
We hope to hear from you soon!
Lauren

How to avoid permission denied on shiny server for other users [duplicate]

I'm trying to make shiny apps available to my coworkers without them having to run or even have R installed.
So I read this webpage
and found this sentence:
If you are familiar with web hosting or have access to an IT
department, you can host your Shiny apps yourself.
under the 'Share as a web page'-section.
How can I do this?
The problem is that my company is bound to certain restrictions regarding web hosting and security and so on, and will not (for now) pay for a shiny-server-pro.
But the sentence above gives me hope to set up something ourselves to convince them.
If your PC and your coworkers PCs belong to the same LAN, this is pretty easy to achieve. Just run your app through:
runApp(host = "0.0.0.0", port = 5050)
The value set through the host argument says to accept any connection (not just from localhost). The port argument can assume any value that you want (just assure to avoid to select ports used by other services like ssh or http). Then, take note of your local IP (if you are under linux, you can see it through ifconfig). Say your IP is 192.168.1.70. Your colleagues can use your app by inserting in the address bar of their browser 192.168.1.70:5050, i.e. your IP followed by : and the port number you selected.
If you want access from outside your LAN, you can direct your router to your PC when someone connect to your public IP through the 5050 port.
Sharing apps over the LAN like this is pretty cool, but it is kind of a hack. I tried it with some co-workers, and it works, but it is more of an office trick than a sustainable solution.
I just finished developing the RInno package for this exact problem, i.e. when a company will not pay for Shiny Server or there are security concerns with cloud services.
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
You might want to have a look at the open source solution shinyproxy.
Using shinyproxy you will have to wrap your apps in a docker container to host them.
Here you can find a guide on how to deploy a shiny app in a docker container (which btw. is a good practice, even without using shinyproxy, to maintain the app dependencies).
There are different authentication and scaling methods available.
I have recently installed Shiny on a Centos 7 Linux OS server we have locally. We used the guide below for the most part.
https://www.vultr.com/docs/how-to-install-shiny-server-on-centos-7
Feel free to ask any questions about setup problems here so anyone else using the guide can see the answers!
We also looked into pushing it up on a AWS server, opted for our own as the content is sensitive. Otherwise both solutions looked similar. The Linux and Shiny system are light, you might be able to run it on the free Amazon server!
Here's another really "hacky" solution. I recently had to deal with the same issue you faced, and wasn't sure how to get some sort of POC in front of the eyes of those who make the decisions. I knew that they could access a particular shared network drive. So I saved the R binaries to that network drive. The app that I wrote was saved on that same network drive. I then wrote a .R file and saved it in the app's working directory that had these lines in it to set the working directory and source the global variables.
contents of app_start.R
setwd("shared/drive/app_directory")
source("./global.R")
runApp("launch.browser=TRUE")
All of this was started by a batch file (if windows, otherwise a .sh file) with one line that had two parts, the absolute filepath to the R binaries on the network drive, and then the .R script above to run the application
# something to the effect of
filepath/to/R/bin/Rscript.exe filePath/to/app_start.R
It did the trick for a POC, but definitely would not be a production-worthy solution.
The Web Hosting Data Apps has some tutorials to host Shiny apps using just systemd or docker and make them globally accesible, you can check them out.

Shiny app on Server: not publish it, only make it run

I am working on an Shiny app in R. My goal is to put in on a server, not on my local pc.
EDIT: my goal is not to publish it on the web, but only make it run on the server locally.
I have installed R on the server, added all the libraries I need, lastly I tried to launch my app that it is quite long, the schema is more or less this:
data preprocessing (with RODBC)
some custom functions
server<- etc.
ui<- etc.
shinyapp(server,ui)
Well in my local pc everything is fine, but on the server I cannot have a result, it is impossible to reach the address.
I decided to do something like this, create the two files called server and ui, and launching them with:
runApp(".../shiny")
Having the idea to use the option of runApp.
Well it is arriving this
ERROR: Error sourcing C:\Users\...\AppData\Local\Temp\Rtmp8YeSOV\file22281c0c2f6d
First of all, this procedure is going to help me?
If so, could you tell me what that error mean?
Thanks in advance.
I'm not sure, but I think it's not possible to reach a shiny app running in a local computer (or server). For that purpose you can use the Shiny Sever, which allow you to put your Shiny apps accessible online.
It seems that your server is a Windows computer, so your options are:
Build Shiny Server from its source code, (maybe a little difficult).
Use a virtual machine like VMware Player (free for non-commercial use) and install Ubuntu or other Linux distribution to use the pre-built binary of Shiny Server. With this option you can restrict the access to only your local network and maybe faster access to your DB's.
Use a DigitalOcean virtual server (for a very reasonable price), in this case you apps will be on the cloud and accesible everywhere.
For option 2 and 3 you can follow the very useful and well written tutorial of Dean Attali about installing and setting up a Shiny Sever. It is for DigitalOcean but is pretty much the same if you decide to use a virtual machine with Linux.
The answer is quite simple, I was using IE as browser: if you use Chrome specifying it on the runApp statement, everything works fine.

Hosting and setting up own shiny apps without shiny server

I'm trying to make shiny apps available to my coworkers without them having to run or even have R installed.
So I read this webpage
and found this sentence:
If you are familiar with web hosting or have access to an IT
department, you can host your Shiny apps yourself.
under the 'Share as a web page'-section.
How can I do this?
The problem is that my company is bound to certain restrictions regarding web hosting and security and so on, and will not (for now) pay for a shiny-server-pro.
But the sentence above gives me hope to set up something ourselves to convince them.
If your PC and your coworkers PCs belong to the same LAN, this is pretty easy to achieve. Just run your app through:
runApp(host = "0.0.0.0", port = 5050)
The value set through the host argument says to accept any connection (not just from localhost). The port argument can assume any value that you want (just assure to avoid to select ports used by other services like ssh or http). Then, take note of your local IP (if you are under linux, you can see it through ifconfig). Say your IP is 192.168.1.70. Your colleagues can use your app by inserting in the address bar of their browser 192.168.1.70:5050, i.e. your IP followed by : and the port number you selected.
If you want access from outside your LAN, you can direct your router to your PC when someone connect to your public IP through the 5050 port.
Sharing apps over the LAN like this is pretty cool, but it is kind of a hack. I tried it with some co-workers, and it works, but it is more of an office trick than a sustainable solution.
I just finished developing the RInno package for this exact problem, i.e. when a company will not pay for Shiny Server or there are security concerns with cloud services.
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
You might want to have a look at the open source solution shinyproxy.
Using shinyproxy you will have to wrap your apps in a docker container to host them.
Here you can find a guide on how to deploy a shiny app in a docker container (which btw. is a good practice, even without using shinyproxy, to maintain the app dependencies).
There are different authentication and scaling methods available.
I have recently installed Shiny on a Centos 7 Linux OS server we have locally. We used the guide below for the most part.
https://www.vultr.com/docs/how-to-install-shiny-server-on-centos-7
Feel free to ask any questions about setup problems here so anyone else using the guide can see the answers!
We also looked into pushing it up on a AWS server, opted for our own as the content is sensitive. Otherwise both solutions looked similar. The Linux and Shiny system are light, you might be able to run it on the free Amazon server!
Here's another really "hacky" solution. I recently had to deal with the same issue you faced, and wasn't sure how to get some sort of POC in front of the eyes of those who make the decisions. I knew that they could access a particular shared network drive. So I saved the R binaries to that network drive. The app that I wrote was saved on that same network drive. I then wrote a .R file and saved it in the app's working directory that had these lines in it to set the working directory and source the global variables.
contents of app_start.R
setwd("shared/drive/app_directory")
source("./global.R")
runApp("launch.browser=TRUE")
All of this was started by a batch file (if windows, otherwise a .sh file) with one line that had two parts, the absolute filepath to the R binaries on the network drive, and then the .R script above to run the application
# something to the effect of
filepath/to/R/bin/Rscript.exe filePath/to/app_start.R
It did the trick for a POC, but definitely would not be a production-worthy solution.
The Web Hosting Data Apps has some tutorials to host Shiny apps using just systemd or docker and make them globally accesible, you can check them out.

Resources