### Install and Start OpenCPU Server Source: https://context7.com/opencpu/server-manual/llms.txt Instructions for setting up the OpenCPU development environment in R and the production cloud server on Ubuntu systems. ```r install.packages("opencpu") library(opencpu) ocpu_start_server() ocpu_start_app("rwebapps/markdownapp") ``` ```bash sudo apt-get update sudo apt-get upgrade sudo add-apt-repository ppa:opencpu/opencpu-2.2 -y sudo apt-get update sudo apt-get install opencpu-server ``` -------------------------------- ### Configure OpenCPU Server Settings Source: https://context7.com/opencpu/server-manual/llms.txt JSON configuration examples for server performance tuning and GitHub authentication tokens. ```json { "httpcache.post": 300, "preload": ["ggplot2", "dplyr"], "timelimit.post": 90, "rlimit.as": 2147483648, "rlimit.fsize": 104857600, "rlimit.nproc": 50 } ``` ```json { "auth_token": "your_github_token", "client_id": "your_client_id", "client_secret": "your_client_secret" } ``` -------------------------------- ### Install R Packages on Server Source: https://context7.com/opencpu/server-manual/llms.txt Methods for installing R packages via source, R console, or precompiled Ubuntu repositories. ```bash wget http://cran.r-project.org/src/contrib/glmnet_1.9-5.tar.gz sudo R CMD INSTALL glmnet_1.9-5.tar.gz --library=/usr/local/lib/R/site-library sudo -i R sudo apt-get install r-cran-xml sudo add-apt-repository ppa:marutter/rrutter3.5 -y sudo add-apt-repository ppa:marutter/c2d4u3.5 -y sudo apt-get update sudo apt-get install r-cran-ggplot2 ``` ```r install.packages("ggplot2") install.packages("glmnet") library(devtools) install_github("dplyr", "hadley") ``` -------------------------------- ### List Installed Packages Source: https://context7.com/opencpu/server-manual/llms.txt Retrieve a list of all R packages installed on the OpenCPU server. ```APIDOC ## GET /ocpu/library/ ### Description Retrieves a list of all R packages installed on the server. ### Method GET ### Endpoint /ocpu/library/ ### Parameters None ### Request Example ```bash curl -L http://your.server.com/ocpu/library/ ``` ### Response #### Success Response (200) - **package_name** (string) - The name of an installed R package. #### Response Example ``` abc abind abn ... ``` ``` -------------------------------- ### Retrieve Package Information via HTTP Source: https://context7.com/opencpu/server-manual/llms.txt Demonstrates how to list installed R packages and access specific package metadata, documentation, and data formats using curl. ```bash curl -L http://your.server.com/ocpu/library/ curl http://your.server.com/ocpu/library/stats/R curl http://your.server.com/ocpu/library/stats/man/rnorm/html curl http://your.server.com/ocpu/library/MASS/data/Boston/json ``` -------------------------------- ### Execute R Scripts and Documents Source: https://context7.com/opencpu/server-manual/llms.txt Demonstrates how to trigger the execution of R scripts, knitr documents, and brew templates via HTTP POST requests. ```bash curl -X POST http://your.server.com/ocpu/library/knitr/examples/knitr-minimal.Rmd curl -X POST http://your.server.com/ocpu/library/brew/example1.brew ``` -------------------------------- ### Access GitHub Packages via OpenCPU Source: https://context7.com/opencpu/server-manual/llms.txt Shows how to list and access R packages hosted on GitHub directly through the OpenCPU API endpoint. ```bash curl http://your.server.com/ocpu/apps/jeroen/ curl http://your.server.com/ocpu/apps/jeroen/curl curl http://your.server.com/ocpu/apps/jeroen/curl/R curl http://your.server.com/ocpu/apps/jeroen/curl/R/curl_fetch_memory curl http://your.server.com/ocpu/apps/jeroen/curl/man/curl_fetch_memory ``` -------------------------------- ### Manage Apache Service for OpenCPU Source: https://context7.com/opencpu/server-manual/llms.txt Provides commands to enable or disable the OpenCPU site in Apache and monitor system logs for troubleshooting. ```bash sudo a2ensite opencpu sudo apachectl restart sudo a2dissite opencpu sudo apachectl restart sudo tail /var/log/apache2/error.log sudo tail /var/log/opencpu/apache_error.log sudo tail /var/log/kern.log ``` -------------------------------- ### Render R Documents via OpenCPU API Source: https://context7.com/opencpu/server-manual/llms.txt Demonstrates how to trigger document rendering (Rmd, brew) using curl requests to the OpenCPU API. Specifies output formats such as docx, html, or odt. ```bash curl http://your.server.com/ocpu/library/knitr/examples/knitr-minimal.Rmd -d format=docx curl http://your.server.com/ocpu/library/knitr/examples/knitr-minimal.Rmd -d format=html curl http://your.server.com/ocpu/library/knitr/examples/knitr-minimal.Rmd -d format=odt curl http://your.server.com/ocpu/library/brew/example1.brew -d output=out.txt ``` -------------------------------- ### Execute Scripts API Source: https://context7.com/opencpu/server-manual/llms.txt Run R scripts, knitr documents, and brew templates via HTTP POST requests. ```APIDOC ## POST /ocpu/library/[package]/[script_path] ### Description Executes various types of R scripts, including standard R scripts (.R), knitr documents (.Rnw, .Rmd), and brew templates (.brew) hosted within R packages. This endpoint is used for server-side script execution. ### Method POST ### Endpoint `/ocpu/library/[package]/[script_path]` ### Parameters #### Path Parameters - **package** (string) - Required - The name of the R package containing the script. - **script_path** (string) - Required - The path to the script file within the package (e.g., `examples/knitr-minimal.Rnw`). #### Query Parameters None #### Request Body None (arguments are typically passed within the script itself or via environment variables if configured). ### Request Example ```bash # Execute a knitr Rnw file curl -X POST http://your.server.com/ocpu/library/knitr/examples/knitr-minimal.Rnw # Execute a knitr Rmd file curl -X POST http://your.server.com/ocpu/library/knitr/examples/knitr-minimal.Rmd # Execute a standard R script curl -X POST http://your.server.com/ocpu/library/knitr/doc/knitr-intro.R # Execute a brew template curl -X POST http://your.server.com/ocpu/library/brew/example1.brew ``` ### Response #### Success Response (200 OK or 201 Created) - The response typically indicates the status of the script execution and may provide links to temporary output files, similar to the 'Call R Functions' endpoint, depending on how the script is designed to output results. ``` -------------------------------- ### Package Information API Source: https://context7.com/opencpu/server-manual/llms.txt Access package contents including R objects, documentation, and data in various formats. ```APIDOC ## Package Information Endpoints ### Description Accesses package contents such as R objects, documentation, and data. Supports various output formats. ### Method GET ### Endpoints - `/ocpu/library/[package]/R` - Lists R functions in a package. - `/ocpu/library/[package]/R/[function]` - Gets specific function information. - `/ocpu/library/[package]/man/[function]/[format]` - Gets manual page in specified format (text, html, pdf). - `/ocpu/library/[package]/data/[data_object]/[format]` - Accesses package data in specified format (json, csv, rda). ### Parameters #### Path Parameters - **package** (string) - Required - The name of the R package. - **function** (string) - Required - The name of the R function or data object. - **format** (string) - Optional - The desired output format (e.g., 'text', 'html', 'pdf', 'json', 'csv', 'rda'). ### Request Example ```bash # List R functions in stats package curl http://your.server.com/ocpu/library/stats/R # Get specific function info curl http://your.server.com/ocpu/library/stats/R/rnorm # Get manual page in text format curl http://your.server.com/ocpu/library/stats/man/rnorm/text # Access package data in JSON format curl http://your.server.com/ocpu/library/MASS/data/Boston/json ``` ### Response #### Success Response (200) - Varies based on the requested resource and format. Can be text, HTML, PDF, JSON, CSV, or R data objects. ``` -------------------------------- ### Generate and Retrieve Graphics Source: https://context7.com/opencpu/server-manual/llms.txt Explains the process of generating plots using R packages like ggplot2 and fetching the output in different image formats with custom dimensions. ```bash curl http://your.server.com/ocpu/library/ggplot2/R/qplot -d "x=[1,2,3,4,5]&y=[8,9,7,8,7]&geom='line'" curl "http://your.server.com/ocpu/tmp/x07a773be/graphics/1/png?width=800&height=500" ``` -------------------------------- ### Customize AppArmor Security Profiles Source: https://context7.com/opencpu/server-manual/llms.txt Commands to manage and debug AppArmor security policies for the OpenCPU server environment. ```bash sudo service apparmor restart sudo tail -f /var/log/kern.log | grep opencpu ``` -------------------------------- ### Execute R Functions via HTTP API Source: https://context7.com/opencpu/server-manual/llms.txt Shows how to invoke R functions using POST requests with form-encoded or JSON parameters, and how to retrieve results in various formats. ```bash curl http://your.server.com/ocpu/library/stats/R/rnorm -d "n=10&mean=100" curl http://your.server.com/ocpu/library/stats/R/rnorm/json -d "n=3" curl http://your.server.com/ocpu/library/stats/R/rnorm -H "Content-Type: application/json" -d '{"n":10, "mean": 10, "sd":10}' ``` -------------------------------- ### Generate Graphics API Source: https://context7.com/opencpu/server-manual/llms.txt Create plots using R and retrieve them in PNG, PDF, or SVG format with customizable dimensions. ```APIDOC ## Generate Graphics Endpoints ### Description Allows the creation of plots using R functions (e.g., `qplot` from `ggplot2`) and retrieval of these graphics in various formats (PNG, PDF, SVG) with options to specify dimensions. ### Method POST (to initiate plot generation), GET (to retrieve the plot) ### Endpoints - `POST /ocpu/library/[package]/R/[function]` - To initiate the plot generation by calling an R plotting function. - `GET /ocpu/tmp/[session_id]/graphics/[graphic_id]/[format]` - To retrieve the generated graphic. ### Parameters #### Path Parameters (for POST) - **package** (string) - Required - The R package containing the plotting function. - **function** (string) - Required - The R plotting function to call (e.g., `qplot`). #### Query Parameters (for GET) - **width** (integer) - Optional - The desired width of the graphic in inches or pixels (context-dependent). - **height** (integer) - Optional - The desired height of the graphic in inches or pixels (context-dependent). - **format** (string) - Required - The desired output format ('png', 'pdf', 'svg'). #### Request Body (for POST) Arguments for the R plotting function, typically form-encoded. ### Request Example ```bash # Create a plot with ggplot2's qplot curl http://your.server.com/ocpu/library/ggplot2/R/qplot \ -d "x=[1,2,3,4,5]&y=[8,9,7,8,7]&geom='line'" ``` ### Response #### Success Response (201 Created - POST) - The response body contains temporary file paths for the plot, including: - `/ocpu/tmp/[session_id]/graphics/[graphic_id]` - `/ocpu/tmp/[session_id]/source` - `/ocpu/tmp/[session_id]/console` - `/ocpu/tmp/[session_id]/info` #### Success Response (200 OK - GET) - The response body is the binary data of the requested graphic format (PNG, PDF, or SVG). #### Response Example (POST) ``` /ocpu/tmp/x07a773be/R/.val /ocpu/tmp/x07a773be/graphics/1 /ocpu/tmp/x07a773be/source /ocpu/tmp/x07a773be/console /ocpu/tmp/x07a773be/info ``` #### Request Example (GET) ```bash # Retrieve graphics in PNG format with custom dimensions curl "http://your.server.com/ocpu/tmp/x07a773be/graphics/1/png?width=800&height=500" ``` ``` -------------------------------- ### Call R Functions API Source: https://context7.com/opencpu/server-manual/llms.txt Execute R functions via HTTP POST, mapping arguments from request parameters or JSON body. ```APIDOC ## POST /ocpu/library/[package]/R/[function] ### Description Executes a specified R function within a package. Arguments can be provided as form-encoded parameters or a JSON request body. The response includes temporary file paths for output, which can then be retrieved in various formats. ### Method POST ### Endpoint /ocpu/library/[package]/R/[function] ### Parameters #### Path Parameters - **package** (string) - Required - The name of the R package containing the function. - **function** (string) - Required - The name of the R function to execute. #### Query Parameters None #### Request Body Arguments for the R function. Can be form-encoded (e.g., `n=10&mean=100`) or a JSON object (e.g., `{"n":10, "mean": 10, "sd":10}`). ### Request Example ```bash # Call rnorm with form-encoded parameters curl http://your.server.com/ocpu/library/stats/R/rnorm -d "n=10&mean=100" # Call with JSON input curl http://your.server.com/ocpu/library/stats/R/rnorm \ -H "Content-Type: application/json" \ -d '{"n":10, "mean": 10, "sd":10}' ``` ### Response #### Success Response (201 Created) - The response body contains temporary file paths for the function's output, including: - `/ocpu/tmp/[session_id]/R/.val` (The primary R object output) - `/ocpu/tmp/[session_id]/stdout` (Standard output) - `/ocpu/tmp/[session_id]/source` (The executed script/function source) - `/ocpu/tmp/[session_id]/console` (Console output) - `/ocpu/tmp/[session_id]/info` (Session information) #### Success Response (200 OK) - Direct Output When requesting output directly in a specific format (e.g., `/json`, `/ascii`), the response is the formatted output. #### Response Example (201 Created) ``` /ocpu/tmp/x032a8fee/R/.val /ocpu/tmp/x032a8fee/stdout /ocpu/tmp/x032a8fee/source /ocpu/tmp/x032a8fee/console /ocpu/tmp/x032a8fee/info ``` #### Response Example (200 OK - JSON) ```json [ 3.05644, 0.38511, 1.11983 ] ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.