I have a general question using R and plumber
. How can I return an image which is a ggplot plot and a table of data (which is essentially a data frame) in the same request? The end result should be an image and beside it a table of data.
I know how to do it separately, but how can it be done together? This is a general question, not regarding some specific code chunk.
Thanks!
Asked
Active
Viewed 427 times
0

Corel
- 581
- 3
- 21
-
Alternative: return the data, and have a second function/endpoint that takes that data-frame to plot it. It takes two calls, but it simplifies your API a little. – r2evans Dec 26 '18 at 16:10
-
@r2evans: Yes but that is what I'm trying to avoid exactly because my script should run on a server so its inefficient to make a separate call for a graph and a table. Being able to return a JSON with both is also an accepted solution for me, if someone knows how to do that (like serializing an image into JSON) I would be happy to know about that. – Corel Dec 26 '18 at 16:25
-
I don't see anything in the plumber docs (I could be wrong) that suggest it supports http pipelining, which to me would be the most generic way to do this. Perhaps you'll need custom JS to be able to parse a manually-constructed base64- (or mime-) encoded image/data combination. – r2evans Dec 26 '18 at 16:55
-
another possibility: return a list, which converts nicely to JSON. One element of the list might be table, and another might be path to saved plot. – Kamil Sijko Jan 29 '20 at 11:08