STAT547-UBC-2019-20 / group05

Repository for our team project (group 05)
0 stars 3 forks source link

Deploying app to Heroku #61

Closed iciarfernandez closed 4 years ago

iciarfernandez commented 4 years ago

Hi @yuliaUU,

I was just going through the guidebook again to remember how we deployed an app to Heroku in class previously, but I'm a bit confused as to how to do this with our repo. My "app" is now on heroku.com and I got to the "deploy branch" step, but it's giving me errors. I guess my questions are:

  1. Where do the required files (Dockerfile, heroku.yml, app.json, init.R, and apt-packages) need to be located within our repo? I first had them in the "scripts" folder but it gave me the error "cannot find a heroku.yml file" on Heroku.com, so I changed them to the root repo folder but I'm not sure that's how I'm supposed to approach that issue?

  2. I am now getting this error, which I don't understand:

=== Fetching app code =!= There were problems parsing your heroku.yml. We've detected the following issues: "build" must validate one and only one schema (oneOf). Found none valid build.docker in body is a forbidden property build.web in body is a forbidden property

Thank you!!

yuliaUU commented 4 years ago

1) all 5 files and app should be in one main folder, and Heroku should be connected to that folder specifically: image

2) not sure about the error, but did you updated init.R and other files to match your app?

yuliaUU commented 4 years ago

also, did you forked the repo and put it outside your project ( e.g. somewhere om desktop for instance) and then do the steps described in the guide/?

iciarfernandez commented 4 years ago

I did fork the repo and put it in a temporary folder I created on my desktop, and I updated my init.R to include all packages that my app.R uses. I now also moved my app.R to the main repo folder like you said above (it was under 'scripts' before), but still getting this error:

=== Fetching app code. =!= There were problems parsing your heroku.yml. We've detected the following issues: "build" must validate one and only one schema (oneOf). Found none valid build.docker in body is a forbidden property build.web in body is a forbidden property

yuliaUU commented 4 years ago

did you check the heroku.yaml is all good and indented properly also, the Dockfile all the app name match?

iciarfernandez commented 4 years ago

I think so? I'm not sure of how to check that.

My heroku.yml looks like this:

build:
  docker:
  web: Dockerfile

And my Dockerfile looks like this:

FROM plotly/heroku-docker-r:3.6.2_heroku18

# on build, copy application files
COPY . /app/

  # for installing additional dependencies etc.
  RUN if [ -f '/app/onbuild' ]; then bash /app/onbuild; fi; 

# look for /app/apt-packages and if it exists, install the packages contained
RUN if [ -f '/app/apt-packages' ]; then apt-get update -q && cat apt-packages | xargs apt-get -qy install && rm -rf /var/lib/apt/lists/*; fi;              

# look for /app/init.R and if it exists, execute it
RUN if [ -f '/app/init.R' ]; then /usr/bin/R --no-init-file --no-save --quiet --slave -f /app/init.R; fi; 

# here app.R needs to match the name of the file which contains your app              
CMD cd /app && /usr/bin/R --no-save -f /app/app.R

My app script is called app.R

yuliaUU commented 4 years ago

how your app is called?

iciarfernandez commented 4 years ago

On Heroku.com I named it phd-satisfaction, is that what you mean?

yuliaUU commented 4 years ago

no, the actual script to run app: is it app.R or smth else?

iciarfernandez commented 4 years ago

It's app.R

yuliaUU commented 4 years ago

everything looks fine then in those apps. what about init.R? what did you put inside?

yuliaUU commented 4 years ago

and after you moved the app, didi you commit and push the changes?

iciarfernandez commented 4 years ago

These are the contents of init.R,

# R script to run author supplied code, typically used to install additional R packages
# contains placeholders which are inserted by the compile script
# NOTE: this script is executed in the chroot context; check paths!

r <- getOption('repos')
r['CRAN'] <- 'http://cloud.r-project.org'
options(repos=r)

# ======================================================================

# packages go here
install.packages('remotes')

remotes::install_github('plotly/dashR', upgrade=TRUE)
install.packages('tidyverse')
install.packages('plotly')
install.packages('gapminder')
install.packages('ggsci')
install.packages('ggplot2')
iciarfernandez commented 4 years ago

yeah I did commit and push the changes, the app is on the main root repo folder both on GitHub and in my local clone in the temporary folder I created in my computer.

yuliaUU commented 4 years ago

let me try and redo your app, and see whether I encounter the same issues, ok?

iciarfernandez commented 4 years ago

sounds good, thank you so much!

yuliaUU commented 4 years ago

I was an easy to fix; first

  1. your .yml file is not indented properly: web should be indented more: that was a source of error
    build:
    docker:
    web: Dockerfile
  2. you init.R loads wrong packages: you don't even yous gapminder, and your app.r have way more libraries than you list there
iciarfernandez commented 4 years ago

Thank you so much! The app seemed to be deploying successfully, but the app doesn't actually display. In regards to your init.R comment, do the dash libraries also have to be loaded? I think that's what I'm confused about

yuliaUU commented 4 years ago

@sciclic yes, all the libraries listed in README to your repo have to be installed. dash is installed with this code:

# packages go here
install.packages('remotes')

remotes::install_github('plotly/dashR', upgrade=TRUE)

you dont need to load any other dash related libraries

iciarfernandez commented 4 years ago

I see, thank you! I thought it only needed to be the libraries that were loaded in the app.R script. I'm trying now once I've updated it and I will let you know if it works. Thanks for all the help @yuliaUU ! :)

iciarfernandez commented 4 years ago

Hi again @yuliaUU, so I added all the libraries in our README to the init.R and deployed the app, the message on Heroku.com says that it was deployed successfully, but this is what shows up when I try to actually open the app

Screenshot (133)

yuliaUU commented 4 years ago

if you type in terminal, heroku logs -- tail, what will you get?

iciarfernandez commented 4 years ago

Screenshot (135)

This is the output of heroku logs --tail in terminal

yuliaUU commented 4 years ago

can you give me a link to updated files, i will have a look

iciarfernandez commented 4 years ago

yes, thank you!

yuliaUU commented 4 years ago

this is what I found H10 error. @firasm , maybe you saw it already and can help with it?

iciarfernandez commented 4 years ago

thank you @yuliaUU, not too sure of how to fix that so we'll wait for @firasm to reply.!

yuliaUU commented 4 years ago

@sciclic can you try again? i changed indenting of .yml. can you run using this one?

iciarfernandez commented 4 years ago

Running it right now! Thank you. Will let you know once it's finished

iciarfernandez commented 4 years ago

Now it's giving me a different error. Would it show up for you with the link phd-satisfaction.herokuapp.com?

Screenshot (136)

iciarfernandez commented 4 years ago

I actually tried reloading a couple times, and now it gives me the same "application error" as before @yuliaUU

iciarfernandez commented 4 years ago

Hey just a small (unsuccessful) update that I deleted the app from Heroku, cloned the repo into a temp folder from scratch again, and repeated the whole process but still not working. I thought maybe that would be the easiest way, but no luck :(

yuliaUU commented 4 years ago

@firasm , we cant seem to pinpoint the issue

yuliaUU commented 4 years ago

Can you try to reduce your datasets by half and run it?

iciarfernandez commented 4 years ago

What do you mean by reduce the datasets by half? Right now I am attempting to deploy from terminal instead, based on this https://devcenter.heroku.com/articles/build-docker-images-heroku-yml#getting-started-existing-app

Thanks for all the help @yuliaUU, sorry we've had so many issues

yuliaUU commented 4 years ago

make the data twice less; for example instead 4000 entries, do 1000. I was just wondering whether it is size related issue or not

iciarfernandez commented 4 years ago

Oh I see. Right now Jacob is trying to deploy it from his end to see if it somehow works for him, otherwise we'll try that! We did reduce the dataset for the app.R script (created a new dataframe called survey_dash.csv with less columns than the original), but I suppose it could still be a size issue

firasm commented 4 years ago

When I try to run it (with debug=TRUE), I get an error,

Invalid argument `value` passed into Slider with ID "ageslider".
Expected `number`.
Was supplied type `string`.
Value provided: "1"
Screen Shot 2020-04-06 at 9 42 52 PM

I think your problem is Line 62:

make_plot2 <- function(ageslider = "1"){

the "1" shouldn't be a string, but a value.

firasm commented 4 years ago

There's also a second bug:

your app$run_server needs to be:

app$run_server(host = "0.0.0.0", port = Sys.getenv('PORT', 8050))

when it's deployed to heroku. Otherwise you will get errors like:

"App boot timeout"

firasm commented 4 years ago

Ok your app now deploys for me: https://test-app-squirrels.herokuapp.com

The last comment I made is most likely the error (I'm not sure what's going with your make_plot2 but it seems to work both ways)

jacobgerlofs commented 4 years ago

@firasm @yuliaUU ,

Thanks for all your help, it seems to be running correctly now! The app$run_server change did the trick, although the make_plot function did not work correctly for me and deployment failed when passing 1 as a value :information_desk_person: Nonetheless, it's working now when passed as a string. Thanks :grin: