https://shiny-survey-demo.herokuapp.com/
Some personal (non-conclusive) learning notes... Google is your friend!
Keep calm and dockerize it or something like that. My personal take-away (from this simple experiment) was that once the app runs in a container on your local machine it is straight forward to publish the app! I guess that's the beauty of containers - once they run, they run. I mean isn't that the point?
Read the docs! They usually know best what they are doing...
In the sense of "Things and packages you want to keep in mind when setting up a public shiny app...". Mainly a list of packages and some random remarks why they are useful.
Build the shiny app as a Package! And preferably write some tests! Leverage usethis
and devtools
(and...?) to set up the files (respectively the repo structure).
config.yml
) as my purpose is to invite people to survey. Could probably be easily extended with sign in form and stuff...config.yml
which then can be imported in R with config::config::get()
..gitignore
(don't track with git and don't push) and .Rbuildignore
(don't embody in package)!
- However, does heroku push only include the files tracked by git??
- Obviously, your
config.yml
needs to be pushed to heroku too...- See f.ex. here: https://stackoverflow.com/questions/50942102/using-gitignore-on-heroku
- Or: https://www.r-bloggers.com/2020/11/deploying-an-r-shiny-app-on-heroku-free-tier/
renv::init()
sets up blank library and keeps track when you install stuff with install.packages()
.Dockerfile
(see Dockerfile for specifics).RPostgres
contains the driver (?) which you leverage in the DBI
package (f.ex. by passing the RPostgres
specific arguments in dbConnect()
)DBI
functionality (usually passing the connection as the first argument)...brochure
package.$USER
to the docker group which now allows me to run docker commands without sudo
. The error disappeared also but might have because of the next issue:FROM in Dockerfile
: Having not yet understood the precise structure of Docker on your system I just realized, that locally I could build on top of a (private) image by specifying FROM private-image
. However, when trying to push to heroku, this was no longer possible (as I think heroku tried to grab it from the Docker hub instead of my local image repo...)..gitignore
.Rbuildignore
: Don't push sensitive stuff to public (and don't include it in the script).Dockerfile
, see first lines there). Read the error message (printed to your terminal)!RUN
and CMD
in your Dockerfile! Use shiny::runApp()
in your Dockerfile (you can also call a script calling a function calling shiny::shinyApp()
)... Also you might have to set the WORKDIR
appropriately! Now to the main point: When the container runs you can map (via the -p
flag in docker run
) the exposed port to your local port (or something like that). And you then can access the App via this local port in your browser. However, heroku sets this exposed port dynamically and publishes the port as an ENV variable. See Dockerfile
for how to handle that!heroku.yml
config in your root. Then (via the CLI) after project initialization you can somehow (google it) register that you are using a containerized solution. Also register your app using a postgres hobby plan.help
is usually the most usefull command! If you don't know what's going on try help
or man
or append --help
to your commands - it helps...
usethis
and devtools
stuff!docker build -t <TAGNAME> .
(point!)docker run -d --rm -p -v <TAGNAME>
(flags!)docker container ls -a
(docker container id is also printed when run)docker stats
docker images
docker rmi <IMAGE>
(id or tag(?))docker logs <CONTAINER-ID
of running container.heroku create
(--stack=container)heroku stack:set container
(or with flag above)git push heroku master
(or whatever branchname you want to push)heroku addons:create heroku-postgresql:<PLAN_NAME>
heroku pg:info
heroku pg:credentials:url DATABASE
(primary database...)heroku pg:psql
heroku open
\d
list tablesheroku pg:psql
!DBI
package.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.