rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.38k stars 256 forks source link

Support plumber.autoreload option #488

Open blairj09 opened 4 years ago

blairj09 commented 4 years ago

Shiny has an option called shiny.autoreload that monitors source files for changes and automatically reloads the Shiny app. It would be nice if Plumber had a similar option.

blairj09 commented 4 years ago

https://github.com/siegerts/drip

schloerke commented 4 years ago

This is a non-R auto reload process. BUT, it looks like it works (untested).

mskyttner commented 3 years ago

A live-reload feature would be very nice to have!

I tried to do some tests, with drip installed in the rstudio/plumber container. I tried using one of the existing bundled examples in the plumber R package that has an entrypoint.R (the example with a counter). It seems drip expects the entrypoint.R to do pr$run() - which seems to clash with the example I was using. I tried just to add that and then got it to run. A couple of reflections from testing this setup (container with latest version of drip + plumber) can be found here: https://github.com/mskyttner/plumber-dripdrop

mskyttner commented 2 years ago

Another variant https://github.com/mskyttner/trickler is using the official plumber container but extends it with inotify-tools which is used to monitor a directory (mounted from the host) with plumber files. A bash script reloads the server automatically when there are changes made to files mounted in the directory. Tested briefly and seems to resolve some issues I had with drip and later versions of plumber (like "createTcpServer: address already in use" on some restarts and dealing with entrypoint.R-files which return a (not running) plumber router object).

m-muecke commented 1 month ago

What currently works quite well for me is using entr with something like the following: ls plumber/*.R | entr -r Rscript plumber/entrypoint.R and just putting that in a Makefile for convenience. Here is good overview for various file watchers, which can also be used: https://anarc.at/blog/2019-11-20-file-monitoring-tools/