Hosting and setting up own shiny apps without shiny server - r

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.

Related

Host ShinyApp from own (Linux) server and own domain

I have programmed a Shiny WebApp and would now like to deploy it myself. So far I have made it available at shinyapps.io. For this I have already set up my own server (a virtual machine running on a datacenter), installed CentOS Server and bought my own domain. Likewise, I have already installed ShinyServer.
However, now I do not really know how to proceed.
In forums I have found various possibilities, which I can not really understand. Therefore I would like to ask here, which possibility is the simplest to provide a Shiny WebApp from the own server under the own domain. This should work without additional costs.
Thanks in advance!
I you have already installed Shinyserver on the CentOs -instance i would advise you to
test if the installation is running properly by checking if the sample app’s are running:
go to a webbrowser on your local machine http://"your-server-address":3838/sample-apps
the test apps should be displayed here , if not:
$ sudo systemctl start shiny-server
check again
copy (scp or clone from git ) your App.R onto the server and put it inside a subdirectory of the /srv/shiny-server/ - directory
check if the app is displayed and works properly (often dependencies are missing) on the server port 3838:
http://"your-server-address":3838/myApp
4: read the
documentation: https://docs.rstudio.com/shiny-server/
quick start guide: https://shiny.rstudio.com/articles/shiny-server.html

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.

Deploying R shiny app as a standalone application [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 months ago.
The community reviewed whether to reopen this question 5 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
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!
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:
GitHub ColumbusCollaboratory: electron-quick-start
GitHub ColumbusCollaboratory: Photon. RStudio Add-in to build Shiny apps utilizing the Electron framework
#TravisHinkelman's blog "Deploying a Shiny app as a desktop application with Electron"
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 :).
You might be interested in DesktopDeployR, a framework for deploying self-contained R-based applications to the desktop.
https://github.com/wleepang/DesktopDeployR
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.
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.

RShiny - How to share app within network

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.

Resources