Logo

0x3d.Site

is designed for aggregating information.
Welcome
check repository here

plumber

R build status CRAN version CRAN RStudio mirror downloads codecov RStudio community

Plumber allows you to create a web API by merely decorating your existing R source code with roxygen2-like comments. Take a look at an example.

# plumber.R

#* Echo back the input
#* @param msg The message to echo
#* @get /echo
function(msg="") {
  list(msg = paste0("The message is: '", msg, "'"))
}

#* Plot a histogram
#* @serializer png
#* @get /plot
function() {
  rand <- rnorm(100)
  hist(rand)
}

#* Return the sum of two numbers
#* @param a The first number to add
#* @param b The second number to add
#* @post /sum
function(a, b) {
  as.numeric(a) + as.numeric(b)
}

These comments allow plumber to make your R functions available as API endpoints. You can use either #* as the prefix or #', but we recommend the former since #' will collide with roxygen2.

library(plumber)
# 'plumber.R' is the location of the file shown above
pr("plumber.R") %>%
  pr_run(port=8000)

You can visit this URL using a browser or a terminal to run your R function and get the results. For instance http://localhost:8000/plot will show you a histogram, and http://localhost:8000/echo?msg=hello will echo back the 'hello' message you provided.

Here we're using curl via a Mac/Linux terminal.

$ curl "http://localhost:8000/echo"
 {"msg":["The message is: ''"]}
$ curl "http://localhost:8000/echo?msg=hello"
 {"msg":["The message is: 'hello'"]}

As you might have guessed, the request's query string parameters are forwarded to the R function as arguments (as character strings).

$ curl --data "a=4&b=3" "http://localhost:8000/sum"
 [7]

You can also send your data as JSON:

$ curl -H "Content-Type: application/json" --data '{"a":4, "b":5}' http://localhost:8000/sum
 [9]

Installation

You can install the latest stable version from CRAN using the following command:

install.packages("plumber")

If you want to try out the latest development version, you can install it from GitHub.

remotes::install_github("rstudio/plumber")
library(plumber)

Cheat Sheet

plumber cheat sheet

Hosting

If you're just getting started with hosting cloud servers, the DigitalOcean integration included in plumber will be the best way to get started. You'll be able to get a server hosting your custom API in just two R commands. To deploy to DigitalOcean, check out the plumber companion package plumberDeploy.

Posit Connect is a commercial publishing platform that enables R developers to easily publish a variety of R content types, including Plumber APIs. Additional documentation is available at https://www.rplumber.io/articles/hosting.html#rstudio-connect-1.

A couple of other approaches to hosting plumber are also made available:

Related Projects

  • OpenCPU - A server designed for hosting R APIs with an eye towards scientific research.
  • jug - (development discontinued) an R package similar to Plumber but uses a more programmatic approach to constructing the API.
R Programming
R Programming
R is a programming language and software environment designed for statistical computing and graphics. It’s widely used in data analysis, machine learning, and academia, offering powerful tools for data visualization and modeling.
R Interface for Bokeh
R Interface for Bokeh
Read Excel Files
Read Excel Files
Arrow R Package
Arrow R Package
Export Data Frames to Excel xlsx Format
Export Data Frames to Excel xlsx Format
Visual Studio Code - Code Editing. Redefined
Visual Studio Code - Code Editing. Redefined
Manipulation of Microsoft Word and PowerPoint Documents
Manipulation of Microsoft Word and PowerPoint Documents
Functions for Tabular Reporting
Functions for Tabular Reporting
Dynamic Function-Oriented Make-Like Declarative Pipelines
Dynamic Function-Oriented Make-Like Declarative Pipelines
Bokeh documentation
Bokeh documentation
R - Visual Studio Marketplace
R - Visual Studio Marketplace
GitHub - Rcpp11/Rcpp11: R and C++11
GitHub - Rcpp11/Rcpp11: R and C++11
Data Apps for Production | Plotly
Data Apps for Production | Plotly
GitHub - tsieger/idendro: Interactive Dendrograms
GitHub - tsieger/idendro: Interactive Dendrograms
GitHub - datastorm-open/visNetwork: R package, using vis.js library for network visualization
GitHub - datastorm-open/visNetwork: R package, using vis.js library for network visualization
GitHub - Lchiffon/wordcloud2: R interface to wordcloud for data visualization.
GitHub - Lchiffon/wordcloud2: R interface to wordcloud for data visualization.
GitHub - REditorSupport/sublime-ide-r: R-IDE: Make Sublime Text a perfect IDE for R
GitHub - REditorSupport/sublime-ide-r: R-IDE: Make Sublime Text a perfect IDE for R
File not found · apache/mxnet
File not found · apache/mxnet
GitHub - sinhrks/ggfortify: Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
GitHub - sinhrks/ggfortify: Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
GitHub - RevolutionAnalytics/checkpoint: Install R packages from snapshots on checkpoint-server
GitHub - RevolutionAnalytics/checkpoint: Install R packages from snapshots on checkpoint-server
GitHub - wesm/feather: Feather: fast, interoperable binary data frame storage for Python, R, and more powered by Apache Arrow
GitHub - wesm/feather: Feather: fast, interoperable binary data frame storage for Python, R, and more powered by Apache Arrow
GitHub - kaneplusplus/bigmemory
GitHub - kaneplusplus/bigmemory
GitHub - IRkernel/IRkernel: R kernel for Jupyter
GitHub - IRkernel/IRkernel: R kernel for Jupyter
GitHub - yihui/animation: A gallery of animations in statistics and utilities to create animations
GitHub - yihui/animation: A gallery of animations in statistics and utilities to create animations
GitHub - rstudio/ggvis: Interactive grammar of graphics for R
GitHub - rstudio/ggvis: Interactive grammar of graphics for R
GitHub - nexr/RHive: RHive is an R extension facilitating distributed computing via Apache Hive.
GitHub - nexr/RHive: RHive is an R extension facilitating distributed computing via Apache Hive.
GitHub - textmate/r.tmbundle: TextMate support for R
GitHub - textmate/r.tmbundle: TextMate support for R
GitHub - renkun-ken/rlist: A Toolbox for Non-Tabular Data Manipulation
GitHub - renkun-ken/rlist: A Toolbox for Non-Tabular Data Manipulation
GitHub - clever-algorithms/CleverAlgorithmsMachineLearning: Defunct
GitHub - clever-algorithms/CleverAlgorithmsMachineLearning: Defunct
GitHub - boxuancui/DataExplorer: Automate Data Exploration and Treatment
GitHub - boxuancui/DataExplorer: Automate Data Exploration and Treatment
GitHub - talgalili/heatmaply: Interactive Heat Maps for R Using plotly
GitHub - talgalili/heatmaply: Interactive Heat Maps for R Using plotly
R Programming
More on R Programming

Programming Tips & Tricks

Code smarter, not harder—insider tips and tricks for developers.

Error Solutions

Turn frustration into progress—fix errors faster than ever.

Shortcuts

The art of speed—shortcuts to supercharge your workflow.
  1. Collections 😎
  2. Frequently Asked Question's 🤯

Tools

available to use.

Made with ❤️

to provide resources in various ares.