Rhttpd-class | R Documentation |
Rhttpd
Rhttpd
is a convenience class for installing and running Rook
applications. It hides the details of starting and stopping the server
and adding and removing Rook
applications from the server.
Users starts by creating one Rhttpd
object, then adding
applications to it, and then starting the server (see the section
“Examples” for a typical session). There are no restrictions on
creating more than one server object, but know that it only manages the
applications that are added to it and not others.
Applications can be added and removed regardless of whether or
not the server is running. Stopping the server does not remove
any applications. Adding an application with the same name as
one already installed simply overwrites the one installed. If
the server is started with no applications installed, it will
install the application named RookTestApp
located in:
system.file('exampleApps/RookTestApp.R',package='Rook')
.
Also, see browseURL
to learn how to get R to
automatically launch your favorite web browser.
NOTE: This version of Rook can only listen on the loopback device.
open(x)
or browse(x)
: Calls browseURL
on the installed Rook application designated by x
. x
is either an integer or a character string. See the output of print()
.
print()
or show()
:Lists the installed Rook applications.
remove(app,all=FALSE)
: Removes the application known to the server. app
can be an RhttpdApp
object previously added, the name of the application as a character string, or an index as a numeric or integer value. See the output of print()
.
full_url(i)
:Returns the absolute url to the application for the given index.
start(listen='127.0.0.1', port=getOption('help.ports'), quiet=FALSE)
: Starts the server on the loopback device and port
. listen
is always character string. Note that if there are no applications added to the object prior to starting, then the RookTestApp located in system.file('exampleApps/RookTestApp.R',package='Rook')
is automatically added.
new()
: Create a new Rhttpd
object.
launch(...)
: Combines the steps of starting the server, creating an RhttpdApp
object, adding it to the server, and opening the app in the browser. ...
argument is passed to RhttpdApp$new()
.
debug()
: Returns the integer value provided by getOption('Rhttpd_debug')
or 0 if the option is NULL.
stop()
:Stops the server.
add(app=NULL,name=NULL)
: Adds a new Rook
application to the server. app
can be an RhttpdApp
object or any Rook
application. name
is a character string and is ignored if app
is an RhttpdApp
object.
RhttpdApp
# Create an Rhttpd object and start the internal web server. Note that # if there are no applications added, then the default RookTest app in # system.file('exampleApps/RookTestApp.R',package='Rook') is automatically # added. s <- Rhttpd$new() ## Not run: s$start(quiet=TRUE) s$browse(1) ## End(Not run) s$print() # Be sure to install the Hmisc package before installing and running # this application. You will want to; it's a pretty good one. # s$add( # app=system.file('exampleApps/Hmisc/config.R',package='Rook'), # name='hmisc') s$add( app=system.file('exampleApps/helloworld.R',package='Rook'), name='hello' ) s$add( app=system.file('exampleApps/helloworldref.R',package='Rook'), name='helloref' ) s$add( app=system.file('exampleApps/summary.R',package='Rook'), name='summary' ) s$print() # Stops the server but doesn't uninstall the app ## Not run: s$stop() ## End(Not run) s$remove(all=TRUE) rm(s)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.