I have developed a C# Windows app that has an embedded R Shiny app through an iframe. This R Shiny app has been deployed on shinyapps.io and works fine. The R Shiny app needs to analyze data from the C# Windows app, and this can be received through a POST request using WebView2, which works like wonder.
The problem
The problem arises when the size of the sent file exceeds 50MB (52428800 bytes in binary). While the size of the sent data (measured on the C# Windows app side) stays below 50Mb, it works perfectly. But after that size is exceeded, altought the iframe containing the R Shiny app starts and loads the interface, within 10-15 seconds it throws an error saying the "Maximum upload size [has been] exceeded":
Here is the code that sends it from the Windows app:
await DataView.EnsureCoreWebView2Async();
var postData = Encoding.UTF8.GetBytes(jsonData);
var postDataStream = new MemoryStream(postData.Length);
postDataStream.Write(postData, 0, postData.Length);
postDataStream.Seek(0, SeekOrigin.Begin);
var request = DataView.CoreWebView2.Environment.CreateWebResourceRequest(DataView.Source.AbsoluteUri,
"POST", postDataStream, "Content-Type: application/json");
DataView.CoreWebView2.NavigateWithWebResourceRequest(request);
And here the code that receives it on the R Shiny side. This code is placed inside the UI part of the Shiny app:
app_ui <- function(request) {
if (identical(request$REQUEST_METHOD, "POST")) {
# Log the reception
log_safe_info("POST request received")
query_params <- parseQueryString(request$QUERY_STRING)
# Read from 'request'
body_bytes <- request$rook.input$read(-1)
result <- jsonlite::fromJSON(rawToChar(body_bytes))
log_safe_info(paste0("Size of the received object: ", object.size(result[[2]])))
}
}
There are some notes to mention here:
- The logs register that this part of the code is reached.
- The code inside the R Shiny app reads the data from the result object, which is an array of 2 positions. The data I need is on the second position, while the first position only contains a timestamp. There is no other data contained inside the object.
- There are no other errors, e.g., related to reading the JSON file, etc.
What have I tried and didn't work
Increasing the R Shiny option maxRequestSize (as suggested by Joe Cheng):
options(shiny.maxRequestSize=100*(1024*1024))
Since I am using golem, this line is added inside the app.R file, before the run_app() function, where all the options are set. I have read over and over that this command should be the solution, but it simply doesn't work. Perhaps I am doing it wrong or something.
Questions I have
- Is the command wrong? Maybe the placement of the command is wrong? Should it be inside the UI part of the app? Or maybe the server?
- Is there any other place within the Shinyapps dashboard where this limit can be changed? Can it be subject to the subscription I have on ShinyApps (Starter Plan)?
- Is there a way to send multiple POST requests through WebView2? My [despair-fueled] idea is to split the data in chunks <50Mb each and send them sequentially. Maybe by doing that the upload size is not hit.