Brewery-class | R Documentation |
Brewery
A Middleware
class for mapping URLs to a directory of files that are subsequently passed to brew
. When a file is brewed, the two variables req
(an object of class Request
) and res
(an object of class Response
) are available for use.
new(url,root,...):
url
is a character string or regexp
on which to match, root
is the name of the directory where brew files reside. Named arguments can be passed in via ...
and will be available within the scope of each brewed file.
Rhttpd
, Builder
, Redirect
, and brew
.
# # This application runs any file found in tempdir() through brew. # s <- Rhttpd$new() ## Not run: s$start(quiet=TRUE) ## End(Not run) cat("<h1>Random Number: <%=rnorm(1)%></h1>", file=file.path(tempdir(),"index.html")) s$add(name="random", app=Builder$new( Brewery$new(url="/",root=tempdir()), Redirect$new("/index.html") ) ) ## Not run: s$browse('random') # Opens a browser window to the app. ## End(Not run) file.remove(file.path(tempdir(),"index.html")) s$remove(all=TRUE) rm(s)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.