dmarx / dispatchr

Run R scripts from the command line in a persisted environment.
0 stars 0 forks source link

Add support for multiple environments #2

Open dmarx opened 7 years ago

dmarx commented 7 years ago

Right now, the api is passing everything into the global environment via GET requests to the endpoint /source_file. Would be cool if we could dispatch to different environments. Maybe something like:

Rscript dispatch.r env1 path/to/script1.r arg0 arg1
# localhost:8080/env1/source_file?fpath=path/to/script1.r&args=arg0&args=arg1

Rscript dispatch.r env2 path/to/script1.r arg0 arg1
# localhost:8080/env2/source_file?fpath=path/to/script1.r&args=arg0&args=arg1

I think this probably makes the most sense, but in reality the environment will probably have to be another query parameter rather than part of the endpoint.

Had to jump through quite a few hoops to figure out how to get stuff to run in the global environment: this might not be super easy. At least not with plumber... meh, who knows.

I'm pretty sure I tried something like this already, but I think the solution would be to, in the API script, grab the environment associated with the endpoint (or create it if it doesn't exist). There's probably a way to do this, although I recall having a lot of issues trying to do it this way.

dmarx commented 7 years ago

Variable routes: https://plumber.trestletech.com/docs/routing/

dmarx commented 7 years ago

Specifying what root folder is associated with a given route would be cool. On the one hand, I could just add a base_path variable to the environment, or something like that (hmm... need to make sure this won't get overwritten). I think I can also specify what folders a plumber server has access to it: https://plumber.trestletech.com/docs/static/