Accessing Shiny App from the WordPress site - r

I have a shiny dashboard, which I have deployed on my custom server (running CentOS). It is deployed by running the following command on the terminal -
> cd "path_to_shiny_app"
> R -e "shiny::runApp(port=XXXX, host = getOption('shiny.host', 'xxx.xx.xx.xxx'))"
On the same server, I also have a WordPress website running. Both Shiny Dashboard and WordPress site will keep running 24x7.
Question 1 - Is there a way I can place a link to Shiny Dashboard on the WordPress site so that my website users can Shiny App through that link?
Question 2 - Is there a limit to the number of users accessing this shiny dashboard in this way?
I am sure someone must have solved it earlier and can help.

Yes, but you need to do more things before generating the link.
Using shiny::runApp directly is not recommended. You want to use a shiny server instead. Depending on the version (free, paid) you use, user counts, load balancing and other settings can be modified accordingly. I personally recommend to use shiny docker instead of installing by yourself.
Once your Shiny apps are running in a localhost port by the shiny server, In order to have it visible for people outside your local network, you need to use a reverse proxy service like nginx or apache to "export" to ports.
Setup your server firewall configs so reverse proxy service can pass the firewall.
Optional, go to your domain manager, create a subdomain for shiny apps.
Additional detailed readings: https://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/
Back to your question
Q1, once you have done above, you should have the Shiny app link, and you can use it on your WordPress.
Q2, there is no user limit, it depends on how powerful your server is. Too many people using the server at the same time may crash it. Paid version of Shiny server has load balancing settings, not sure about the free version.

Related

ERR_EMPTY_RESPONSE shiny server

I am currently hosting a number of shiny apps on a shiny-server open source on a centos7 distro. All the apps were/are working fine but for one of the apps when I try to go to the url I get the following message:
This page isn't working
<ip.address> did not receive any data.
ERR_EMPTY_RESPONSE.
All the other shiny apps hosted on the same shiny server are working just fine. I checked /var/log/shiny-server and there is no log file for this App. As the other apps are working fine, I dont think its a port issue.
The only difference between other apps and this one is that it was used the most by its users. Is there some restriction/limit on shiny-server for runtime? I can't figure out what the problem is. The app runs fine on RStudio Server and if I copy it into a new directory in /srv/shiny-server/ with a different name, it also works fine.
A couple of thoughts:
If a process closes successfully, then shiny deletes the log files. So it's possible you may be missing some log files. You may override this with preserve_logs, see here. Your users may be triggering some error through their interactions with the app, but other sessions are successful, so shiny deletes the log files.
Shiny creates one process per app be default, but an unlimited number of session (see here). This means that if your app is the one that is used the most by users, each user is generating a new session. And if the app is computationally intensive, then some of the user sessions may be getting backlogged which might trigger the ERR_EMPTY_RESPONSE. You can fix this by using Docker to spin up a process for each user. Here are some options, I've found shinyproxy to be the most intuitive.

Publish R-markdown (Shiny doc) on remote Shiny server (in docker) - basic question

This is basic educational question. I am confused about some fundamental concepts.
So I work on my local machine and I created R-markdown (Shiny doc) . Now, if I want to publish it, I just click in the top right corner (where I previously established account at shinyapps.io and connected to it). Well due to some reasons, I would like to publish it different place then shinyapps.io.
So my understanding is that I can accomplish it if I install and configure shiny server in docker. Is this accurate? Do I need Shiny proxy as well.
I also read about dockerizing shiny app, but this sound like to much work creating container instance for each app.
The publishing button works with shinyapps.io or rstudio connect. If you'd like to publish an app using free shiny-server, you won't be able to use the publishing button. You'll need to put a copy of the app in the folder tree you configure shiny-server to publish from. This is a bit more manual. You don't necessarily need Docker, but you do need a Linux computer to run shiny-server. If you want to put your apps in docker containers, you'll want to check out shinyproxy if you're trying to go the free route. RStudio has great paid options if you want to go that route.

box_auth() without localhost

I'm trying to use the boxr package to link my box account to R-Server.
I get as far in the box_auth() instructions as step 3 from the box pdf https://cran.r-project.org/web/packages/boxr/boxr.pdf
A window pops up and I authorise connection then I get the error 'Safari can't connect to the server'.
I have no knowledge of how apache or web development works so forgive my naivety, I've come to understand the problem is I don't have localhost set up on my Mac.
I'm unable to turn these features on because it requires admin rights and my company won't allow users to have this.
Is there something else I can put in the redirect_uri box apart from localhost that will allow this to authenticate?
Thanks
The issue i had was mostly that authenticating box through R-Server isn't supported. https://github.com/brendan-r/boxr/issues/23
To get around this I used my personal laptop to authenticate locally then uploaded the .Renviron and .boxr-oauth files to R server (which is the advice in the github post)
This was slightly tricky as R wasn't showing the .boxr-oauth file but I managed to copy it to a folder, zip the folder, then upload that to R-Server.
Now running the box_auth() function authenticates as it should.
As of v0.3.5 (November 2019) boxr has a new alternative authentication method designed for remote servers, box_auth_service(), that closes issue 23. It's slightly is different than the oAuth way, because it uses "Service" accounts as the actors instead of the "User" account. But the "Service" accounts are what's needed to maintain security within a organization, so we opted for that. Please open an issue on the repo if you run into any issues.

Shiny putting app into production

I have created my first Shiny app and i want to share it with people.
I have a folder which contains my ui.R file and my Server.R file.
I have managed to get a server for it and install Shiny Server and it runs pretty well. In fact I have written the shiny app in the web browser.
My question is where do I save the scripts on the shiny server so that I can send the link to people and it will just load up as a website (assuming they have credentials?
Thank you for your time.
I found another question similiar to the one i was looking for.
Hosting LAN Shiny apps run from command line
This answers the question by specifiying that i should move my test scripts into production by saving them /srv/shiny-server/myApp
Which server do you use? Perhaps AWS (Amazon)? Then you can upload it in one of the folders on your server. In the case of Amazon, you do it through S3 Browser.
You can use a domain name to redirect you to the specific folder where you keep your shiny apps. Each shiny app should have its own sub-directory where you keep server and ui scripts. Then you load your shiny name like this:
yourdomain.com/sub_directory_where_shiny_script_are_located
Don't forget to adjust your directories in the script, so that when you load any data, it loads the data located on ubuntu server, for example.
if(Sys.info()[['user']] %in% c("ubuntu","shiny") ) {
load("/a2cka/ShinyApps/sub_directory_shin_app_/data.csv}

Shiny Server User/UserGroup

Please suggest a clean(er) way of adding a user (like myself) to Shiny Server running on Ubuntu. I found this link: Setting up shiny User permissions but would like more advice on this. And I don't want to host RStudio server, just want to host Shiny server. Also can I run Tomcat along with Shiny server on the same machine?
I think you may be misunderstanding what that link is saying. You're not setting up different users for the Shiny server, you're setting up users on your computer, and managing them in such a way that you keep track of permissions for files you create on the computer. The important thing is to make sure the "shiny" user on your computer (which will be the one hosting your shiny server apps, unless you modify the default settings) has the correct permissions to access the files it will need when running those apps.
When you run a Shiny app, you won't be logged in as a user per se, rather the "shiny" user will host the computation for you, and deliver any output to you through your browser interface.
To my knowledge, unless you're using Shiny Server Pro, you won't have the ability to specify different users when using the apps (this is different to a "session", which is another topic).
When you create a shiny app, and install it (by moving it to the "/srv/shiny-server" folder), you'll need to make sure the user "shiny" on your computer has read access to that file at the very least. If your app involves reading data files from your computer, make sure the "shiny" user has read access to those too. If your app involves writing to files on our computer, make sure the "shiny" user also has write permission for those files.

Resources