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

Some guidance on V8 and JS with R in general #28

Open
debsush opened this issue Jul 19, 2016 · 1 comment
Open

Some guidance on V8 and JS with R in general #28

debsush opened this issue Jul 19, 2016 · 1 comment

Comments

@debsush
Copy link

debsush commented Jul 19, 2016

Hi,

This is not an issue but rather a query on how to use the new V8 version to call R functions from within Javascript

I have read the article and loved it and so would like to know how can the new feature be leveraged in my particular case cited below.

I have a shinyapp where I am using a JS charting library. I am computing the data in R and passing it to the Javascript using shinyjs. Shinyjs uses V8. This works great. Now as my data size increase or users from remote geographies try to access my app, I am having to transfer huge datasets from my server.ui to the client-side javascript library and network bandwidth is slowing my app down. I was wondering if I could transfer the entire computation to the client side by enabling the execution of the Rscript functions within JS. Then I can pass the computed data (which I think would now reside on the client-side) directly to the charting library and enable me to bypass the transfer of heavy data between server and the client. Let me know if I am making sense so far or I am conceptually inaccurate (which can well be the case given my limited knowledge in this field).

So, if the above theory makes sense, I would like to run the R functions from a particular package within JS.

Current Scenario:

  1. When app loads, the R script pulls an initial data set and passes it to the JS charting library using shinyJS. This is when the initial transfer of data between server and client takes place and this cannot be avoided.
    Say the initial data is a data frame DF.
    DFJson <- jsonlite::toJSON(DF)
    Now pass this json to the JS charting library
  2. For subsequent calculations based on users input, all I need to do is use the same json which I have passed onto the JS and run some R functions on it and then pass it back to the charting library. In the current scenario, I am computing the revised data within R and passing it back to JS
DF<-newDF(DF)
DFJson <- jsonlite::toJSON(DF)
newDF<-function(data){
#convert the data frame to xts
data<-as.xts(data)
SMA<-quantmod::SMA(data,20)
data<-merge(data,SMA)
#convert it back to data frame
data<-as.data.frame(Date=index(data),coredata(data))
return(data)
}

Now this new data with an additional column is being transferred to the JS library. This time again the transfer between server and client is subject to network bandwidth. I would like to bypass these subsequent transfers by computing the new data within JS using the R function newDF that I have defined. Please note that DF has dependency on the R library quantmod.

  1. Do I make sense at all.
  2. If yes, can I perform the above strategy using the new V8.
  3. Do I need to place my function newDF within gloabl.R
  4. Appreciate a small example of writing newDF within JS using v8 console.R API

Regards
SD

@debsush
Copy link
Author

debsush commented Jul 20, 2016

I mentioned the same issue @ shinyJS and the package owner confirmed that it was outside the scope of shinyJS since shinyJS uses pure javascript

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