Title: | Turn 'Plumber' APIs into 'Tableau' Extensions |
---|---|
Description: | Build 'Plumber' APIs that can be used in 'Tableau' workbooks. Annotations in R comments allow APIs to conform to the 'Tableau Analytics Extension' specification, so that R code can be used to power 'Tableau' workbooks. |
Authors: | James Blair [aut, cre], Joe Cheng [aut], Toph Allen [aut], Bill Sager [aut], RStudio [cph, fnd], Tableau [cph] |
Maintainer: | James Blair <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-12-14 02:50:08 UTC |
Source: | https://github.com/rstudio/plumbertableau |
arg_spec()
and return_spec()
are used to create arguments for
tableau_handler()
. They describe the data type of the arg or return value,
and can return a human-readable description that can be used to generate
documentation.
arg_spec( type = c("character", "integer", "logical", "numeric"), desc = "", optional = grepl("\\?$", type) ) return_spec(type = c("character", "integer", "logical", "numeric"), desc = "")
arg_spec( type = c("character", "integer", "logical", "numeric"), desc = "", optional = grepl("\\?$", type) ) return_spec(type = c("character", "integer", "logical", "numeric"), desc = "")
type |
A string indicating the data type that is required for this argument. |
desc |
A human-readable description of the argument. Used to generate documentation. |
optional |
If |
A tableau_arg_spec
object, which is a list containing details about
the Tableau argument expectations
A tableau_return_spec
object, which is a list containing details
about the values expected to be returned to Tableau
mock_tableau_request()
creates a JSON object formatted like a request from
Tableau. The JSON object it returns can be pasted directly into the "Try it
out" field in the Swagger documentation for an endpoint to test its
functionality.
mock_tableau_request(script, data, ...)
mock_tableau_request(script, data, ...)
script |
String indicating the path to the endpoint to be called |
data |
A list or dataframe that is serialized to JSON |
... |
Additional arguments passed to |
Behind the scenes, Tableau sends all requests to the /evaluate
endpoint.
Each request is a JSON object containing two items: script
and data
.
plumbertableau uses script
to specify an individual endpoint to call, and
passes the arguments in data
on to the function at that endpoint.
A JSON object that can be passed to a Tableau endpoint
mock_tableau_request("/loess/predict", mtcars[,c("hp", "mpg")])
mock_tableau_request("/loess/predict", mtcars[,c("hp", "mpg")])
Most of the time, you won't call this function directly. Instead, you'll
place it at the end of a Plumber router, under a #* @plumber
annotation,
with no trailing parentheses or arguments. This tells Plumber to use the
function to modify the router object.
tableau_extension tableau_extension(pr)
tableau_extension tableau_extension(pr)
pr |
A plumber router |
A modified plumber router that functions as a Tableau Analytics Extension
## Not run: library(plumber) library(plumbertableau) #* Capitalize incoming text #* @post /capitalize function(req, res) { dat <- req$body$data toupper(dat) } #* @plumber tableau_extension ## End(Not run)
## Not run: library(plumber) library(plumbertableau) #* Capitalize incoming text #* @post /capitalize function(req, res) { dat <- req$body$data toupper(dat) } #* @plumber tableau_extension ## End(Not run)
Creates an object that can translate arguments from Tableau to R, and return values from R to Tableau.
tableau_handler(args, return, func)
tableau_handler(args, return, func)
args |
A named list describing the arguments that are expected from
valid Tableau requests. The names in the named list can be any unique
variable names. The values in the named list must each be either a string
indicating the expected data type for that argument ( |
return |
A string indicating the data type that will be returned from
|
func |
A function to be used as the handler function. Code in the body
of the function will automatically be able to access Tableau request args
simply by referring to their names in |
A tableau_handler
object that is a validated version of the
provided func
with additional attributes describing the expected arguments
and return values
Simulates invoking a Tableau extension function from a Tableau calculated
field SCRIPT_*
call. Intended for unit testing of plumbertableau extensions.
tableau_invoke(pr, script, ..., .toJSON_args = NULL, .quiet = FALSE)
tableau_invoke(pr, script, ..., .toJSON_args = NULL, .quiet = FALSE)
pr |
Either a tableau_extension style Plumber router object, or, the filename of a plumber.R that implements a Tableau extension. |
script |
The script string that identifies the plumber route to invoke.
(Equivalent to the first argument to |
... |
Zero or more unnamed arguments to be passed to the script. |
.toJSON_args |
Additional options that should be passed to
|
.quiet |
If |
The object that was returned from the request, JSON-decoded using
jsonlite::parse_json
.
pr_path <- system.file("plumber/stringutils/plumber.R", package = "plumbertableau") tableau_invoke(pr_path, "/lowercase", LETTERS[1:5])
pr_path <- system.file("plumber/stringutils/plumber.R", package = "plumbertableau") tableau_invoke(pr_path, "/lowercase", LETTERS[1:5])