Shiny putting app into production - r

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}

Related

Best way to distribute an R/Shiny app to be run by a user on local computer?

I have developed a Shiny app for a user at a different location. This app may eventually be hosted in the cloud but for now a single user will run the application locally on their computer. What is the preferred way to share the application and also make it easy to maintain/update the scripts?
Do I need to instruct the user to install R, RStudio, all of the packages used by the application, and copy the R scripts, etc, to a local directory, and then include directions about how to run from the RStudio interface?
I'm intrigued by the runGitHub option, which seems very appealing, with one problem: It wouldn't be wise to add the file containing API tokens in the GitHub repository. Is there a way for the code to look for that specific file locally instead of in the repository?
Thank you!
You can use {dotenv} to store the secrets. For example,
create a .env in your app root folder.
In the file
username=xxxxxx
token="xxxxxx"
Make a copy of this file called .env-template.
Add .env but not .env-template to .gitignore.
Fill your real tokens in .env since this file will not be uploaded to github.
In R, use
# load secrets
library(dotenv)
load_dot_env('.env')
# to get values
Sys.getenv("username")
Sys.getenv("token")
Tell users to fill their real tokens in .env-template and rename it to .env
to use runGithub or runGist
The demo is very simple, just to get the secret token locally while running app from a remote address.
Your app code
library(shiny)
server <- function(input, output, session) {
print(Sys.getenv("token")) # just print out the token on console
}
shinyApp(div(), server)
User code will be like
library(shiny)
### first run without following 4 lines and then uncomment following and run again
### watch the difference on console
# library(dotenv)
# dotenv_file <- tempfile()
# cat('token=12345', file = dotenv_file)
# load_dot_env(dotenv_file)
###
runGist('https://gist.github.com/lz100/f54d59901a56a051770edd77e1324f21')

Unsure where image_write downloads to in shinyapps.io

I'm attempting to make a public shinyapps.io website, and I'm trying to use image_write to create a file into a local directory.
The following code works on my local R studio code:
image_write(im.resized, path = paste0(output_file_directory, file_name), format = "jpg")
When I run the code on the shinyapps.io website, the code runs without error, but I'm not sure where it downloads the file to. I know that the output_file_directory part isn't the issue, so I'm a little lost. Any help would be much appreciated!
On shinyapps.io it is not possibly to store permanently data, due to:
"Shinyapps.io is a popular server for hosting Shiny apps. It is designed to distribute your Shiny app across different servers, which means that if a file is saved during one session on some server, then loading the app again later will probably direct you to a different server where the previously saved file doesn’t exist."
See here:
https://shiny.rstudio.com/articles/persistent-data-storage.html

Shiny server on EC2: URL lists folder content instead of displaying app

[Sorry, newbie here!]
I've just installed R server, shiny server on an ubuntu EC2 instance. I have left the shiny-server.conf intact, except that I added: preserve_logs true;. The sample app was working fine.
I have removed /srv/shiny-server/index.html and /srv/shiny-server/sample-apps.
I have linked my app files from my /home/myapp directory to /srv/shiny-server/myapp. The app files consists of a single apps.R, a footer.html, and a small dataset .Rds, and a www/style.css file.
When I navigate to http://[myip]:3838/ the only thing is the directory listing; the only folder is : myapp. When I click to http://[myip]:3838/myapp/ , I see the directory listing as well. That is, I see the content, and I can download each of them. BUt I see no evidence of the app running. If I click on apps.R, my browser downloads the file.
PS: the app works fine when tested in Rstudio, or deployed on Shinyapps.io
If anyone from the future reads this, I wish you heard the loud headslap when I realized my app single-file should be called app.R, not apps.R (which makes a lot of sense in retrospect).

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.

Access to Shiny app in another computer within the same network

I've created a Shiny app that runs perfectly when I run it in my computer (I have the "ui.R" and "server.R" files in a directory of my desktop).
But I want to other people in my workplace (also using R and RStudio) can also run it.
I copy the "ui.R" and "server.R" files to a directory in another computer, so anyone with the permissions can access this app.
The problem is that when I move this files to other computer's folder I can't run the app anymore. It gives me the error "No Shiny application exists at the path..."
I set the working directory to this new path where I put the files, so I don't know where the problem is. I have lecture and writing permissions to this folder.
I'm using Windows 7.
A much easier way would be keep server.R and ui.R in one script without copying to a specific area.
shinyApp(ui = ui, server = server)

Resources