Webtools is a set of utilities to build APIs, web applications, and
other web services in R. It is primarily based on
{fiery}
as the main backend web
framework.
This package is available from my R Universe.
install.packages("webtools", repos = "https://tjpalanca.r-universe.dev")
All the features provided by {fiery}
and its associated packages
{reqres}
and {routr}
through sthe main App
object:
Create handler functions for events in the event cycle, such as for authentication, pre-, or post-processing.
Schedule asynchronous execution to increase concurrency especially with polling and long-running operations.
Setting global headers, application data, and client id conversion.
Logging with different events and message types.
Websocket message connection, receiving, and sending.
Attaching routes to the application via the {routr}
package,
with automatic attachment and detachment during application
start and stop.
along with some improvements:
Attach static files using {httpuv}
’s staticPath
which takes
place on the I/O thread and does not block up the main R
session, improving performance.
Configuration has a whole separate place from application data or metadata.
Plugin interface that is more flexible: (a) can be detached, (b) can contain methods in addition to adding handlers only.
Handler, router, and static path functions can have metadata attached to them so that they can be removed or inspected as a group.
Help on the various arguments and return types of the handlers
through the $events
active field.
Methods are prefixed for easier discovery and autocomplete, and methods return the object itself when appropriate, allowing for method chaining.
exports some instantiated objects for easier autocompletion when constructing handler functions.
HTML Building and Rendering Utilities
html_render()
is an optimized version that renders tags from
{htmltools}
into character vectors, for use in server side
rendering applciations through HTMLPlugin
.
html_template()
, html_mustache()
, and html_tags()
help in
building HTML pages natively or via text templates sprinkled
with R inserts.
Development Utilities
dev_app()
) or static pages (dev_html()
).Robustness
The starting point is the App
object. This contains the base for the
webserver. Afterwards, you can attach some plugins for specific
functionality.
We add subclasses of the main App
class for different types of
applications:
AsyncPlugin
- capabilities for asynchronous execution of tasks to
ensure that the main app thread remains responsive and available
even under high concurrency.
TestPlugin
- Provide a set of utilities to test requests going
through the application logic, for profiling or testing.
PerfPlugin
- Provide a set of utilities for measuring the
performance of Applications, from specific routes and handlers to
the whole application.
HTMLPlugin
- an application that serves HTML generated via
{htmltools}
; pairs well with server side frameworks like
Hotwire or htmx.
All of this is built on top of the excellent
{fiery}
,
{reqres}
, and
{routr}
by Thomas Lin
Pedersen.
{plumber}
is a package for
building Web APIs, supported by RStudio and built on top of
{httpuv}
.
{ambiorix}
is another web
server implementation built on top of {httpuv}
.
{shiny}
is the standard way to
quickly build web applications in R.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.