Table of contents
1.
Introduction
2.
PlumberTableau Extensions in R-studio
2.1.
Installation
3.
What can plumbertableau Extensions Do?
3.1.
An Example of Loess Regression
3.2.
How is it used in testing? 
4.
Frequently Asked Questions
4.1.
I thought Tableau already supported R.
4.2.
Why would I use this instead of RServe?
4.3.
Is RStudio Connect required?
5.
Conclusion
Last Updated: Mar 27, 2024

PlumberTableau Extensions in R-studio

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Let's ensure we understand the foundational concepts before delving further into the subjects. Here is a brief introduction if you are unfamiliar with R-studio.

PlumberTableau Extension in R-Studio

An integrated development environment (IDE) for R is called R-Studio. The IDE is a graphical user interface where you can write quotes, view the results, and see the variables created during programming.

✔️ R Studio is software that is both open source and paid for.

✔️ Additionally, there are desktop and server versions of R-Studio.

✔️ R Studio is also accessible on various operating systems, including Windows, Linux, and macOS.      

This article explains the details of PlumberTableau Extensions in R-studio in which we will talk about RStudio, PlumberTableau Extensions in R-studio, and how it is used in testing.

 

Without further ado, let's get started.

PlumberTableau Extensions in R-studio

Through Tableau Analytics Extensions, plumbertableau allows you to execute external R code directly from Tableau workbooks. To do this, you create a plumbertableau extension, a Plumber API with additional annotations—comments beginning with the symbol #*.

library(plumber)
library(plumbertableau)
#* @apiTitle String utilities
#* @apiDescription Simple functions for mutating strings
#* @post /capitalize
function(str_value) {
  toupper(str_value)
}
#* @plumber
tableau_extension

 

The computed fields in Tableau use plumbertableau extensions. We have added the custom URL stringutils to RStudio Connect and published our extension there. We could write the following into a Tableau calculated field or simply copy and paste it from the automatically generated code samples to use our capitalization extension. (In actual usage, you'll probably substitute allusions to Tableau data for "Hello ninjas").

SCRIPT_STR("/stringutils/capitalize", "Hello ninjas")

 

Tableau must have access to the extension before you can use it. With the help of plumbertableau, R developers may quickly publish a range of R content formats using the commercial publishing platform RStudio Connect. By ensuring that requests from Tableau are routed to the appropriate extension, Connect enables you to host numerous extensions. You can host plumbertableau extensions on your servers as well.

Installation

💁 Plumbertableau can be downloaded from CRAN, or the most recent development version can be downloaded from GitHub.

# From CRAN
install.packages("plumbertableau")

# From GitHub
remotes::install_github("rstudio/plumbertableau")

library(plumbertableau)

What can plumbertableau Extensions Do?

Tableau's requests are answered by extensions called plumbertableau. An endpoint, which approximately equates to an R function, and one or more arguments, which often include Tableau data, are provided by Tableau in a request.

The amount of data that an extension must return must match the number of observations in the arguments it has been given. It can do tasks like text transformation or make predictions about Y values from a matrix of X values using a model. For example, a plumbertableau extension can't accept an integer indicating how many elements should be sampled and then return a vector of that length.

An Example of Loess Regression

Let's begin with some basic R code that fits a smooth line across the input data and plots the outcome using the loess() function.

a <- seq(1, 10, length.out = 100)
b <- 1/a^2 + rnorm(length(a), sd = 0.05)
fit <- loess(b ~ a, span = 0.75)
b_fit <- predict(fit, data.frame(a, b))

# Display the data and the prediction..
plot(a, b)
lines(a, b_fit)

How is it used in testing? 

💁 Plumbertableau makes use of Plumber's capacity to produce API documentation in Swagger.

 

1️⃣ Once you've created an API, you may test it locally using the Swagger user interface. The Run API button in RStudio or plumber::plumb("path/to/plumber.R")$run() in the R console can be used to launch the API. 

2️⃣ To expand the /predict endpoint, click on it. The example request can then be modified by clicking "Try it out," and it can be sent by clicking "Execute."

3️⃣ The JSON object that makes up a Tableau request has two components. These are shown in the straightforward fake request that plumbertableau supplies following Tableau's requirements.

{
  "script": "/predict",
  "data": {
    "_arg1": [
      0
    ],
    "_arg2": [
      0
    ]
  }
  • script: a string that designates an endpoint. Plumbertableau uses this string value to correctly redirect requests to the specified endpoint after Tableau sends all extension requests to the /evaluate endpoint in the background.
  • data: a container object for the arguments the function uses at the endpoint. This data is parsed by plumbertableau, which then sends it to the R code. Tableau names parameters _arg1, _arg2,..., argN instead of allowing them to be named explicitly. R receives arguments in the order that they are presented. In this scenario, the underlying R function will receive an x from _arg1 and a y from _arg2.

Frequently Asked Questions

I thought Tableau already supported R.

Rserve is the foundation of the current Tableau support for R as an analytics extension. With this method, Rserve must be configured in a separate environment before being passed R code from Tableau computed fields to be run by Rserve.

Why would I use this instead of RServe?

Instead of forcing the Tableau user to create and submit R code in a plain text field from Tableau, the method proposed here enables the calling of specified endpoints. As a result, Tableau users can be independent of the people who create the extensions. 

Is RStudio Connect required?

RStudio Connect was specifically considered when creating this package, however it can be used without it as well.

Conclusion

Congratulations on finishing the blog! We have discussed the details of PlumberTableau Extensions in R-studio, in which we talk about RStudio, PlumberTableau Extensions in R-studio, and how it is used in testing.

We hope this blog has helped you enhance your knowledge of PlumberTableau Extensions in R-studio. If you'd like to learn more, Check out the following links:

🔥 R Programming Language

🔥 Apache vs. NGINX

🔥 R programming interview questions.

 

Please refer to our guided pathways on Code studio to learn more about DSACompetitive ProgrammingJavaScriptSystem Design, etc. Enroll in our courses, and use the accessible sample exams and questions as a guide. For placement preparations, look at the interview experiences and interview package.

Please upvote 🏆 our blogs 🎈 if you find them helpful and informative!

Happy coding🤗

Live masterclass