Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying to self-hosted Shiny Server #145

Closed
GregSutcliffe opened this issue Sep 5, 2019 · 10 comments
Closed

Deploying to self-hosted Shiny Server #145

GregSutcliffe opened this issue Sep 5, 2019 · 10 comments

Comments

@GregSutcliffe
Copy link

Hi there - new to Golem but enjoying the workflow :)

I'm looking for guidance on deploying a Golem-based Shiny app to a self-hosted Shiny server. As far as I can see in 03_deploy.R the functions are all aimed at RStudio hosting or Docker, so how would I go about deploying this to my Linux VM?

For contrast, in my non-Golem apps, I would just rsync the project over to /srv/shiny-server/apps/ and make sure the dependencies are available. What's the right approach for Golem? Do I need to write a minimal app.R which is similar to the one generated in golem::add_shinyserver_file and get Shiny to launch that (given that I will have installed my Golem package too)?

Thanks!

@ColinFay
Copy link
Member

ColinFay commented Sep 5, 2019

Hey @GregSutcliffe,

Thanks for giving {golem} a spin!

Deploying to Shiny Server should be pretty straightfoward if you did this with a standard application before. Right now there are two ways to do it: copy the full golem folder, or use the built package.

With the first solution, the idea is to have the whole {golem} folder, with the app.R generated by golem::add_shinyserver_file(), at the right spot on the Shiny Server.

The app.R generated by this function behaves as a drop-in replacement for your previous app.R.

So to sum up :

  • Create your golem but don't build the tar.gz
  • generate the app.R with golem::add_shinyserver_file()
  • copy the root folder of your app to the right folder on the server scp ~/mygolem /distant/server/folder (or with rsync or anything)
  • (don't forget to touch restart.txt)

And this should do the trick.

Second option:

  • create the golem && build the tar.gz
  • upload the tar.gz and install it on the server
  • create an app.R that simply has thenameofyourapp::run_app()

Let me know if this works

@GregSutcliffe
Copy link
Author

GregSutcliffe commented Sep 5, 2019

Thanks for the fast reply!

So if I understand (1) correctly, that means app.R is in a subdirectory, from Shiny Server's perspective, right? Will it find it there (in app/) or do I need to move it to the project root?

I'm just getting my head around Shiny modules - as soon as I have a basic app running, I'll try the deploy and report back!

EDIT: Update - my mistake, app.R is in the root dir already. I misread where it had ended up. Everything makes a lot more sense now :)

@GregSutcliffe
Copy link
Author

It's probably worth mentioning that my non-Golem apps use renv to keep dependencies under control - if I use renv within Golem, does that affect either option?

@GregSutcliffe
Copy link
Author

So I have a vary basic app (one static plot in a module, one table in app_server/ui.R), and it works in RStudio, via run_dev.R and via app.R.

When I use method (1) to deploy to my server (rsync the project, renv::restore the deps), and then go to the URL in my browser, I'm getting errors (the UI starts but then disconnects after drawing the h2 header, which suggests a code error) - but Shiny doesn't appear to be logging the errors. Even if I set golem.app.prod = FALSE in app.R, I don't get a logfile in /var/log/shiny-server/apps.

I know this is likely something weird on my end, but do I need to do anything special for logging from a Golem app?

@GregSutcliffe
Copy link
Author

Just had a try with method (2) - installed the built package tgz on my server and I'm seeing the same behaviour. The package works locally, but on the server it disconnects, and I cannot get it to log why. Any pointers welcome :)

@GregSutcliffe
Copy link
Author

OK, I have the app working now - there was, of course, a typo in some of the startup code. There are logs coming from the reactive parts of the app (i.e things like "stat_bin() using bins = 30. Pick better value with binwidth." from geom_histogram() etc.

Having fixed that, I've re-tested both methods, and both work fine. I'll probably go with option (2) as I can push the package to a Git repo and use renv and remotes::install_gitlab to get the package.

Thanks!

@cparsania
Copy link

cparsania commented Oct 8, 2019

I am facing problem to what mentioned above. I am using workflow 2) as generated by the function golem::add_dockerfile() given in the 03_deploy.R. I am using rocker/r-apt:bionic instead of rocker/tidyverse and also added necessary libraries to the Dockerfile. THe final line on the Dockerfile is CMD R -e "options('shiny.port'=8080,shiny.host='127.0.0.1');myApp::run_app()" The image build successfully. When I start container using docker run myApp:tagName it generates logs as expected but stops at http://127.0.0.1:8080. When I hit url in the browser it says can't connect to the server. Am I missing something here ?? I haven't tried workflow 1) as I find workflow 2) more handy.

@VincentGuyader
Copy link
Member

Hi

Can you please show us :

Your dockerfike
Le complete docker run instruction you use

And the docker logs <conaiterid> you have after launching your docker.

@cparsania
Copy link

cparsania commented Oct 8, 2019

Hi, it was very silly mistake. After taking dig into container-host port expose I figured it out. I did not mentioned option -p while running the container. So final docker file i used is

FROM rocker/r-apt:bionic

RUN apt-get update && \
  apt-get install libcurl4-openssl-dev libv8-3.14-dev  libssl-dev libxml2-dev libxslt-dev libudunits2-dev libproj-dev libgdal-dev libfontconfig1-dev libcairo2-dev -y

COPY ./requirement_bin.txt .
RUN cat requirement_bin.txt | xargs apt-get install -y -qq

COPY ./myApp.tar.gz /app.tar.gz
RUN R -e 'devtools::install_local("/app.tar.gz" , dependencies=TRUE,  build = FALSE ,repos=BiocManager::repositories() )'
EXPOSE 80
CMD R -e "options('shiny.port'=80,shiny.host='0.0.0.0');myApp::run_app()"

and command to launch the container is docker run -p 3232:80 myApp:tag

This solved the problem.

Thanks a lot.

========= EDIT=======

It is worth mentioning that, the above setup does not attach packages which are under the Depends tag of package DESCRIPTION file. In my case I explicitly load shinyBS package using library call. I changed final line of Dockerfile to

CMD R -e "options('shiny.port'=80,shiny.host='0.0.0.0');library(shinyBS); myApp::run_app()"

@ColinFay
Copy link
Member

ColinFay commented Nov 26, 2019

Thanks for your inputs :)

This seems solved, closing now, feel free to reopen if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants