yihui / servr

A simple HTTP server in R
https://cran.rstudio.com/package=servr
278 stars 35 forks source link

How to use handler? #58

Closed etiennebacher closed 3 years ago

etiennebacher commented 3 years ago

Hello, I want to run a command each time a file is changed but before httw() serves the files. I think the argument handler should be appropriate for that but I don't understand the second part of its description: "a function to be called every time any files are changed or added under the directory; its argument is a character vector of the filenames of the files modified or added".

So far, I'm doing something like:

servr::httw(
   "docs/site",
   handler = system("cd docs && mkdocs build -q")
)

This doesn't work and I couldn't find any example in the docs or online. Could you give an example of how to use it?

Thanks in advance

yihui commented 3 years ago

The handler should be a function. What you provided is a call, not a function.

servr::httw(
   "docs/site",
   handler = function(files) {
    system("cd docs && mkdocs build -q")
  }
)

In the future, you may consider asking questions on Stack Overflow or RStudio Community: https://yihui.org/issue/ Thank you!