Executing an R function in OpenCPU using filename parameters

Is there a way to allow users to execute a custom R function with personalized arguments through a web-based platform? Additionally, the option to upload local files for use should be available.

Prior attempts to achieve this goal using OpenCPU were successful. The user's code is encapsulated within an ocpu.Snippet and sent alongside specified arguments args during the following call:

ocpu.call(
    'do.call',
    {
        'what': snippet,
        'args': args
    },
    session => /* processing of return value and console output */
);

This method has proven effective with various argument types thus far.

However, upon testing file uploads, some limitations have been revealed:

  1. The modified JavaScript wrapper (without alerts) can only recognize files at the topmost level, causing issues when attempting to pass a file object within an existing set of arguments (args = { file: File }). In contrast, directly calling ocpu.call('read.csv', args, ...) successfully triggers detection of file: File.
  2. It appears that OpenCPU mandates file uploads in multipart/form-data format, rendering nested file structures incompatible with this requirement.
  3. One potential alternative involves creating a custom R function that facilitates the incorporation of used files as primary arguments, enabling their seamless transfer to the designated function.

This dilemma prompts the search for a solution, particularly pertaining to the development of such a function and exploring alternative methods for remotely invoking a customized function while managing its arguments. Any suggestions on how to address this complexity would be greatly appreciated.

Answer №1

After some experimentation, I discovered that creating the function was actually quite simple:

functionCall <- function(func, ...) {
  return(do.call(func, list(...)))
}

Once the function was added to OpenCPU, it could be invoked using

args = {
  func: snippet,
  x: firstArg,
  y: secondArg,
  // any number of additional arguments
}

opencpu.call(
  'functionCall',
  openCpuArgs,
  callback
);

I ran a test with a snippet that executed read.csv and it successfully displayed the content instead of throwing an error.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the functionality of this JQuery Popup?

I'm facing an issue with my JQuery Popup. When the "Login" button is clicked, it hides the Login popup but doesn't show the Sign Up popup. How can I make sure that clicking on "Login" hides the Login popup and shows the Sign Up popup accordingly? ...

Navigating to a Different Page with Props in ReactJS

When setting up the route, I passed props like this: <Route path="/getFilePage" exact component={GetFilePage} CourseName={props.CourseName} /> On the main page, I used this code to redirect: return <Redirect to={{ pathname: &a ...

Exporting dependencies' dependencies in Angular 2 through multi-providers

Utilizing a multi-provider is the next step I'm considering in order to export both dependencies of my dependency along with itself, allowing for them to be injected into a component simultaneously. For example, when setting up a component: import { ...

Searching for a specific value within a hash in MongoDB

I am working with MongoDB documents formatted like this: { "_id": ObjectId("5406e4c49b324869198b456a"), "phones": { "12035508684": 1, "13399874497": 0, "15148399728": 1, "18721839971": 1, "9831132110 ...

JavaScript Loading Screen - Issues with window.onload functionality

I am currently working on creating a loading screen for my project. I need to use JavaScript to remove the CSS property "Display: none" from the page, but for some reason, my code is not functioning as expected. The Issue: I discovered that using window. ...

Determining the width of error bars in a line plot created with ggplot2

I have a set of data that includes standard errors, and I am looking to visualize them with error bars. Here is the code I currently have: # generating sample data hod <- data.frame(h = c(1:24,1:24,1:24), mean = 1:(24*3) + runif(24*3, 0, 5),ci = runif ...

Is it possible to generate a new array by combining the keys of one array object with the values of another array object?

I have a situation with two arrays set up like this arr1 = [ { 'name':'Victoria Cantrell', 'position':'Integer Corporation', 'office':'Croatia', 'ext' ...

Retrieve the Object from the array if the input value is found within a nested Array of objects

Below is the nested array of objects I am currently working with: let arrayOfElements = [ { "username": "a", "attributes": { roles:["Tenant-Hyd"], groups:["InspectorIP", "InspectorFT"] } }, { ...

sending functions into angular as opposed to using 'function()'

Lately, I've been immersing myself in Angular development. One thing that caught my interest was the idea of using a declared function instead of a generic "function() {}" placeholder, particularly in scenarios like handling promise callbacks. I encou ...

Commit to persevering until you achieve success

I'm currently working with native node.js Promises and did not find any useful information in this thread. Essentially, I am dealing with a function that looks like this: var foo = foo (resolve, reject) { return obj .doA() .doB() ...

How can I configure Select2 to begin searching alphabetically?

I'm currently using select2 for tag searching within my article tracking application, and I've noticed an issue. When typing 'm' or 'mi', the expected behavior would be for tags like 'migrations' to appear first. How ...

BootStrap Collapsible Menu

Hello, I am having an issue with a Bootstrap button. I have implemented the "collapse" feature in a menu, and when I click on one button to collapse it, everything works fine. However, when I try to collapse another button while one is active, it pushes t ...

What are some ways to resolve the issue of HTML tables populating randomly?

I am currently working on retrieving the latitude and longitude of a location from an excel sheet input, and then displaying the data in an HTML table. Although I am able to obtain the correct coordinates, they are not appearing in the correct column as ...

Optimal approach for incorporating controller As with UI Router

Currently working on a small search application using AngularJS and Elasticsearch. I am in the process of transitioning the app from using $scope to controller As syntax. I have implemented UI Router for managing routes/states. I have been attempting to us ...

The installation of Zoo for R appears to have been completed, however it is showing an error stating that the object 'zoo' cannot be found

Having trouble installing the zoo library despite successful installations of ggplot2, xts, and numerous other libraries. Zoo is throwing an error for the first time. What could be causing this issue? > install.packages("zoo") trying URL 'http:// ...

The TouchableOpacity function is triggered every time I press on the Textinput

Every time I press on a text input field, the login function is called This is the touchable statement: <TouchableOpacity style={InputFieldStyle.submitButton} onPress={this.login(this.state.email, this.state.password)}> <Text ...

The Turbolinks:load event is not triggering when a remote True call is made using Rails and jQuery

I've got a basic js file located at app/assets/javascripts/media_preview_script.js $(document).on('turbolinks:load', function() { $("#cat").on('click', function() { showBrowseInput() }) }) function showBrowseInput () { d ...

Creating an expandable table in JavaScript without relying on jQuery

I have a question that I can't seem to find the answer to. Despite numerous Google searches showing jquery solutions, I'd rather stick with vanilla JavaScript as I'm new to it and want to master it before moving on to libraries. My goal is t ...

Modifying the structure of a JSON object

After receiving a JSON object response from the server, I am looking to transform it into a different format using PHP: {"query":"hi", "suggestions":["history","hilton","hilton hhonors","hillary clinton", "hickory farms","hip2save","hitler","hipaa"] } T ...

Adding elements to an array appears to cause the previously created object to react

I am encountering a situation where once I add an object to an array, it becomes reactive to any changes made. // actions.js export const addToCart = ({ commit }) => { commit('addToCart'); // successfully updates the state setTimeout ...