Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct specification of tableauArg and tableauReturn #83

Open
Dan-C-Reed opened this issue Jul 8, 2022 · 0 comments
Open

Correct specification of tableauArg and tableauReturn #83

Dan-C-Reed opened this issue Jul 8, 2022 · 0 comments

Comments

@Dan-C-Reed
Copy link

Dan-C-Reed commented Jul 8, 2022

Say I have an R function that I wish to turn into an API for Tableau and I'd like to use this (awesome!) package. My function doesn't require any arguments and returns a data frame that contains a variety of types. A toy example is included below.

library(plumber)
library(plumbertableau)

#* @apiTitle An example
#* @apiDescription Simple example function
#* @tableauArg x:[logical] A dummy variable
#* @tableauReturn [integer] Returning some stuff
#* @post /mtcars
function(x) {
  mtcars[1:3, ]
}

# The Plumber router modifier tableau_extension is required
#* @plumber
tableau_extension

When I run this API (through Swagger), I get the following:

  {
    "mpg": 21,
    "cyl": 6,
    "disp": 160,
    "hp": 110,
    "drat": 3.9,
    "wt": 2.62,
    "qsec": 16.46,
    "vs": 0,
    "am": 1,
    "gear": 4,
    "carb": 4,
    "_row": "Mazda RX4"
  },
  {
    "mpg": 21,
    "cyl": 6,
    "disp": 160,
    "hp": 110,
    "drat": 3.9,
    "wt": 2.875,
    "qsec": 17.02,
    "vs": 0,
    "am": 1,
    "gear": 4,
    "carb": 4,
    "_row": "Mazda RX4 Wag"
  },
  {
    "mpg": 22.8,
    "cyl": 4,
    "disp": 108,
    "hp": 93,
    "drat": 3.85,
    "wt": 2.32,
    "qsec": 18.61,
    "vs": 1,
    "am": 1,
    "gear": 4,
    "carb": 1,
    "_row": "Datsun 710"
  }
]

This is exactly what I want. Fantastic!

Question 1

Note that I have included tableauArg despite my function not needing any arguments. If I omit this and the argument to my function, I get the following:

Error: Tableau argument and return data types must be specified.

Is there a correct way to omit arguments if they are not needed or do I always have to include a dummy argument like above?

Question 2

Similarly, I must include a data type for tableauReturn. I specify that the return type is an integer, but actually the data frame includes a mixture of integers, doubles, and strings. In Swagger, at least, the response above looks good. How should I specify mixed response data types, like shown in the above example?

Any help would be greatly appreciated and kudos on a stellar package!


Edit:

To follow up on Question 2: it looks like this specifies the SCRIPT_* function that Tableau uses (e.g., SCRIPT_INT in the example above since I specify @tableauReturn [integer]). Given that this is how Tableau and plumbertableau interact, presumably there's no way around this besides returning all data as strings (SCRIPT_STR) and doing the type conversion in Tableau?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant